简体   繁体   中英

How to select column of dataframe using numbers

At the moment I am selecting columns the usual way:

`df$column1`

But I want to loop through the columns of my dataframe into a plot function, and when I use the method:

`df[,1]`

I get the error:

Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous. Error in is.finite(x): default method not implemented for type 'list'

So what would be the best way to select columns of the dataframe so that I can easily loop through the columns and avoid this error.

You can access dataframe columns using double square brackets eg df[[1]] prints the first column. For more info on why/how/etc, see Dave Tang's blog post: https://davetang.org/muse/2013/08/16/double-square-brackets-in-r

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM