[R] Data Extraction

Muhuri, Pradip (SAMHSA/CBHSQ) Pradip.Muhuri at samhsa.hhs.gov
Thu Nov 22 16:31:40 CET 2012


Petr,

You have shown a solution that is the simplest.

Thanks and regards,

Pradip Muhuri
Beginner useR

________________________________________
From: PIKAL Petr [petr.pikal at precheza.cz]
Sent: Thursday, November 22, 2012 9:33 AM
To: Muhuri, Pradip (SAMHSA/CBHSQ); r-help at r-project.org
Subject: RE: Data Extraction

Hi

do you want this?

> df1[complete.cases(df1),]
   X1 X2 X3 X4 X5
2   8  8  3  2 10
6   8  6  7 10  1
11  4  5  5 10  8
12  6  1  7  8  4
17  5  7  3  1  3
18 10  7  3  8  7
19  7  5  3  5  6
20 10  5  2  4  6

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Muhuri, Pradip (SAMHSA/CBHSQ)
> Sent: Thursday, November 22, 2012 3:11 PM
> To: Muhuri, Pradip (SAMHSA/CBHSQ); r-help at r-project.org
> Subject: [R] Data Extraction
>
> Hello,
>
> I would appreciate if someone could help me resolve the following:
>
> 1. df1[!is.na( X1 | X2 | X3 | X4 | X5),][,1:5] # This does not work
>
> 2. Is these message harmful?  The following object(s) are masked from
> 'df1 (position 3)':
>     X1, X2, X3, X4, X5
>
> Thanks,
>
> Pradip Muhuri
>
>
> #Reproducible Example
> set.seed(5)
> df1<-data.frame(matrix(sample(c(1:10,NA),100,replace=TRUE),ncol=5))
> attach (df1)
> #delete rows if any of them NA for X1
> df1[!is.na( X1),][,1:5] # This works
>
> #delete rows if any of them NA for X1, X2, X3, X4 or X5 df1[!is.na( X1
> | X2 | X3 | X4 | X5),][,1:5] # This does not work
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list