子集化数据帧时选择未定义的列 [英] Undefined columns selected when subsetting data frame
本文介绍了子集化数据帧时选择未定义的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框, str(data)
显示更多关于我的数据框,结果如下:
I have a data frame, str(data)
to show more about my data frame the result is the following:
> str(data)
'data.frame': 153 obs. of 6 variables:
$ Ozone : int 41 36 12 18 NA 28 23 19 8 NA ...
$ Solar.R: int 190 118 149 313 NA NA 299 99 19 194 ...
$ Wind : num 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
$ Temp : int 67 72 74 62 56 66 65 59 61 69 ...
$ Month : int 5 5 5 5 5 5 5 5 5 5 ...
$ Day : int 1 2 3 4 5 6 7 8 9 10 ...
但是,例如,当我想将 Ozone
的数量子集上面14时,我使用下面的代码,它给我一个错误:
However, for example, when I want to subset the amounts of Ozone
above 14 I use the following code which gives me an error:
> data[data$Ozone > 14 ]
框架
(数据,数据$ Ozone> 14):未选定的列
Error in
[.data.frame
(data, data$Ozone > 14) : undefined columns selected
推荐答案
你想要那个条件为真的行,因此你需要一个逗号:
You want rows where that condition is true so you need a comma:
data[data$Ozone > 14, ]
这篇关于子集化数据帧时选择未定义的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文