[R] split data with missing data condition

Petr PIKAL petr.pikal at precheza.cz
Fri Oct 15 15:07:47 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 15.10.2010 15:00:46:

> you can do the following:
> 
> mat <- cbind(x = runif(15, 50, 70), y = rnorm(15, 2))
> mat[sample(15, 2), "x"] <- NA
> 
> na.x <- is.na(mat[, 1])
> mat[na.x, ]
> mat[!na.x, ]

Or if you have missing data in several columns and you want select only 
those which are complete use complete.cases

mat[complete.cases(mat},]
mat[!complete.cases(mat},]

Regards
Petr

> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> On 10/15/2010 2:45 PM, Jumlong Vongprasert wrote:
> > Dear all
> > I have data like this:
> >                x          y
> >    [1,] 59.74889  3.1317081
> >    [2,] 38.77629  1.7102589
> >    [3,]       NA  2.2312962
> >    [4,] 32.35268  1.3889621
> >    [5,] 74.01394  1.5361227
> >    [6,] 34.82584  1.1665412
> >    [7,] 42.72262  2.7870875
> >    [8,] 70.54999  3.3917257
> >    [9,] 59.37573  2.6763249
> >   [10,] 68.87422  1.9697770
> >   [11,] 19.00898  2.0584415
> >   [12,] 60.27915  2.5365194
> >   [13,] 50.76850  2.3943836
> >   [14,]       NA  2.2862790
> >   [15,] 39.01229  1.7924957
> >
> > and I want to spit data into two set of data,  data set of nonmising 
and
> > data set of missing.
> > How I can do this.
> > Many Thanks.
> > Jumlong
> >
> >
> 
> -- 
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/
> 
> ______________________________________________
> 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