使用因子变量删除数据框中的行。

时间:2017-04-17 03:42:25

标签: r

此时我对列表,因素和数据框架的理解是耍弄的。我想准备没有第一行的数据框〜“====”

head(dats)
    V1      V2  V3  V4  V5  V6  V7   V8      V9     V10     V11          V12
1 ==== ======= === === === === === ==== ======= ======= ======= ============
2 WMAU 08/0000  26  24  89   0   0 10.0  FEW010  SCT140  BKN270             
3 WMAU 07/2300                                                              
4 WMAU 07/2200                                                              
5 WMAU 07/2100                                                              
6 WMAU 07/2000                                                              

结果欲望;

head(dats)
    V1      V2  V3  V4  V5  V6  V7   V8      V9     V10     V11          V12
1 WMAU 08/0000  26  24  89   0   0 10.0  FEW010  SCT140  BKN270           
2 WMAU 07/2300                                                              
3 WMAU 07/2200                                                              
4 WMAU 07/2100                                                              
5 WMAU 07/2000 

我尝试了dats [, - 1]& dats [-1],但它删除了整个dats $ v1。

       V2  V3  V4  V5  V6  V7   V8      V9     V10     V11          V12
1 ======= === === === === === ==== ======= ======= ======= ============
2 08/0000  26  24  89   0   0 10.0  FEW010  SCT140  BKN270             
3 07/2300                                                              
4 07/2200                                                              
5 07/2100                                                              
6 07/2000

获取信息,

class(dats)
[1] "data.frame"
mode(dats)
[1] "list"
typeof(dats)
[1] "list"
str(dats)
'data.frame':   26 obs. of  12 variables:
 $ V1 : Factor w/ 2 levels "====","WMAU": 1 2 2 2 2 2 2 2 2 2 ...
 $ V2 : Factor w/ 26 levels "=======","07/0000",..: 1 26 25 24 23 22 21 20 19 18 ...

请帮助。谢谢。

0 个答案:

没有答案