R: Undefined Columns Selected Error when Subsetting DF

依然范特西╮ 提交于 2019-12-13 05:56:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32301354/r-undefined-columns-selected-error-when-subsetting-df

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!