Reputation: 411
I have a dataframe data with the following structure:
Classes ‘tbl_df’ and 'data.frame': 4391 obs. of 53 variables
When I try to subset it to get the top 100 rows using
data100 = data[1:100,]
I get this error:
Error in `[.data.frame`(X[[i]], ...) : undefined columns selected
What could be the reason?
Upvotes: 0
Views: 1729
Reputation: 411
Found the answer - I needed to use
as.data.frame(data)
before subsetting because tbl_df is not subsettable the same way as a data frame. This was needed due to using dplyr earlier and it outputting a table instead of a df.
Upvotes: 1