[R] split data with missing data condition
jim holtman
jholtman at gmail.com
Fri Oct 15 15:01:24 CEST 2010
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.good
x 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.bad
x 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?
More information about the R-help
mailing list