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 -- Jumlong Vongprasert Institute of Research and Development Ubon Ratchathani Rajabhat University Ubon Ratchathani THAILAND 34000 [[alternative HTML version deleted]]
Try this: split(as.data.frame(DF), is.na(DF$x)) On Fri, Oct 15, 2010 at 9:45 AM, Jumlong Vongprasert <jumlong.ubru@gmail.com> 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 > > > -- > Jumlong Vongprasert > Institute of Research and Development > Ubon Ratchathani Rajabhat University > Ubon Ratchathani > THAILAND > 34000 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
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, ] 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/
Try this:> a <- read.table(textConnection(" x y+ 59.74889 3.1317081 + 38.77629 1.7102589 + NA 2.2312962 + 32.35268 1.3889621 + 74.01394 1.5361227 + 34.82584 1.1665412 + 42.72262 2.7870875 + 70.54999 3.3917257 + 59.37573 2.6763249 + 68.87422 1.9697770 + 19.00898 2.0584415 + 60.27915 2.5365194 + 50.76850 2.3943836 + NA 2.2862790 + 39.01229 1.7924957"), header=TRUE)> a <- as.matrix(a) > # good data > a.good <- a[complete.cases(a),, drop=FALSE] > a.bad <- a[!complete.cases(a),, drop=FALSE] > a.goodx y [1,] 59.74889 3.131708 [2,] 38.77629 1.710259 [3,] 32.35268 1.388962 [4,] 74.01394 1.536123 [5,] 34.82584 1.166541 [6,] 42.72262 2.787088 [7,] 70.54999 3.391726 [8,] 59.37573 2.676325 [9,] 68.87422 1.969777 [10,] 19.00898 2.058441 [11,] 60.27915 2.536519 [12,] 50.76850 2.394384 [13,] 39.01229 1.792496> a.badx y [1,] NA 2.231296 [2,] NA 2.286279>On Fri, Oct 15, 2010 at 8:45 AM, Jumlong Vongprasert <jumlong.ubru at gmail.com> 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 > > > -- > Jumlong Vongprasert > Institute of Research and Development > Ubon Ratchathani Rajabhat University > Ubon Ratchathani > THAILAND > 34000 > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
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 nonmisingand> > 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.