Help with a line of my R Code

Hello...
I am new to R and have an assignment to complete and I keep on getting the following message
Error in [.data.frame(hr, c("Turn1", "Turn2", "Turn3", "Turn4")) :
undefined columns selected
Not sure what the message means this is the original code that I typed into R
alpha(hr[c("Turn1","Turn2","Turn3","Turn4")])

I am not sure what alpha(hr[c.....is asking?

Thanks for taking the time to read my question...

I guess you are trying to select the columns Turn1, Turn 2, etc. from the data frame hr. When you subset a data frame using [ , you have to provide both rows and columns, designating the rows first and then the columns. You have not chosen any rows. If you want all rows, you can write

hr[, c("Turn1","Turn2","Turn3","Turn4")]

Edit: Yarnabrina is correct in the post below that the comma is not necessary. My response above is not helpful.

Is there a possibility that the hr dataframe does not contain the columns you're using? Please note that these are case sensitive. For example, check

mtcars[c("MPG", "CYL", "DISP")]
#> Error in `[.data.frame`(mtcars, c("MPG", "CYL", "DISP")): undefined columns selected

vs

mtcars[c("mpg", "cyl", "disp")]
#>                      mpg cyl  disp
#> Mazda RX4           21.0   6 160.0
#> Mazda RX4 Wag       21.0   6 160.0
#> Datsun 710          22.8   4 108.0
#> Hornet 4 Drive      21.4   6 258.0
#> Hornet Sportabout   18.7   8 360.0
#> Valiant             18.1   6 225.0
#> Duster 360          14.3   8 360.0
#> Merc 240D           24.4   4 146.7
#> Merc 230            22.8   4 140.8
#> Merc 280            19.2   6 167.6
#> Merc 280C           17.8   6 167.6
#> Merc 450SE          16.4   8 275.8
#> Merc 450SL          17.3   8 275.8
#> Merc 450SLC         15.2   8 275.8
#> Cadillac Fleetwood  10.4   8 472.0
#> Lincoln Continental 10.4   8 460.0
#> Chrysler Imperial   14.7   8 440.0
#> Fiat 128            32.4   4  78.7
#> Honda Civic         30.4   4  75.7
#> Toyota Corolla      33.9   4  71.1
#> Toyota Corona       21.5   4 120.1
#> Dodge Challenger    15.5   8 318.0
#> AMC Javelin         15.2   8 304.0
#> Camaro Z28          13.3   8 350.0
#> Pontiac Firebird    19.2   8 400.0
#> Fiat X1-9           27.3   4  79.0
#> Porsche 914-2       26.0   4 120.3
#> Lotus Europa        30.4   4  95.1
#> Ford Pantera L      15.8   8 351.0
#> Ferrari Dino        19.7   6 145.0
#> Maserati Bora       15.0   8 301.0
#> Volvo 142E          21.4   4 121.0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.