简体   繁体   English

查看R中具有NA的列

[英]View columns with NAs in R

Hei, after I've already got so many helpful advices here, I'd like to ask a question concerning detecting NAs - is there any possibility to view the ROWS of a dataframe which include NAs? 嘿,在这里已经获得了很多有用的建议之后,我想问一个有关检测NA的问题-是否有可能查看包含NA的数据帧的ROWS? The problem is that my dataframe's really huge so 问题是我的数据框非常大,所以

is.na(data_frame) is.na(data_frame)

doesn't show me all the rows (not even nearly), so I only know how many NAs there are and in which columns they are but I would really like to know, whether they are in the same rows - which mean that they possibly cause each other. 并没有显示所有行(甚至不是全部),所以我只知道有多少个NA和它们在哪些列中,但我真的很想知道它们是否在同一行中-这意味着它们可能引起彼此。 As an example for my data, I'll just give you the head of the dataframe, if you need more then tell me 以我的数据为例,如果您需要更多数据,请告诉我

  transect_id year day month      LST precipitation Quarter
1       TR001 2010 191     7 30.62083             0       3
2       TR001 2010 191     7 30.62083             0       3
3       TR001 2010 191     7 30.62083             0       3
4       TR001 2010 191     7 30.62083             0       3
5       TR001 2010 191     7 30.62083             0       3
6       TR001 2010 191     7 30.62083             0       3
    SumPre average.temp  MinTemp  MaxTemp prev.temp prev.Precip
1 1.895143     30.78058 27.73995 33.54386  30.43515           0
2 1.895143     30.78058 27.73995 33.54386  30.43515           0
3 1.895143     30.78058 27.73995 33.54386  30.43515           0
4 1.895143     30.78058 27.73995 33.54386  30.43515           0
5 1.895143     30.78058 27.73995 33.54386  30.43515           0
6 1.895143     30.78058 27.73995 33.54386  30.43515           0
                     species regional_gam prop_pheno_sampled
1           Pontia daplidice      0.00000          0.4496937
2 Polyommatus icarus zelleri      0.00000          0.3952952
3       Gonepteryx cleopatra      1.30963          0.4731522
4           Anaphaeis aurota      0.00000          0.3731392
5         Carcharodus alceae      0.00000          0.1646973
6            Euchloe belemia      1.40654          0.3373209

If I could see the rows with the NAs I could eg check, whether there are NAs for the LST (landscape surface temperature) in the same lines as NAs in the MaxTemp - so it would be obvious that one causes the other. 如果我可以看到带有NA的行,则可以例如检查LST(景观表面温度)是否与MaxTemp中的NA位于同一行中-因此很明显,一个引起了另一个。

I hope I got my question clear :-) Thanks in advance! 我希望我的问题清楚:-)预先感谢!

What I always use is 我一直使用的是

df[rowSums(is.na(df))>0,]

This gives you all rows with at least one NA . 这样,所有行都至少具有一个NA It should be also fairly efficient since rowSums is a really fast base function. 由于rowSums是一个非常快速的base函数,因此它也应该相当有效。

Or for columns 或专栏

df[,colSums(is.na(df))>0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM