R:未定义的列选择DF时的错误 [英] R: Undefined Columns Selected Error when Subsetting DF

查看:3513
本文介绍了R:未定义的列选择DF时的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的数据框架数据:

I have a dataframe data with the following structure:

Classes ‘tbl_df’ and 'data.frame':  4391 obs. of  53 variables

当我尝试使用

data100 = data[1:100,]

我收到这个错误:

Error in `[.data.frame`(X[[i]], ...) : undefined columns selected

可能是什么原因?

推荐答案

找到答案 - 我需要使用

Found the answer - I needed to use

as.data.frame(data)

在子集之前,因为tbl_df不是子集,作为数据帧。这是需要的,因为早期使用dplyr,它输出一个表而不是df。

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.

这篇关于R:未定义的列选择DF时的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆