[R] How to view un-sampled data from a randomly sampled dataset

arun smartpink111 at yahoo.com
Wed Oct 23 21:17:13 CEST 2013


HI,
You may try:
set.seed(432)
 dat1 <- data.frame(Col1=1:150,Col2=rnorm(150))
 y <- dat1[sample(1:nrow(dat1),40,replace=FALSE),]
x <- dat1[-as.numeric(row.names(y)),]
 dim(x)
#[1] 110   2
intersect(row.names(x),row.names(y))
#character(0)

#or
 x1 <- dat1[!row.names(dat1) %in% row.names(y),]
 identical(x,x1)
#[1] TRUE



A.K.



Hi there- 

I have a 150 row dataset (data). I create "y" a randomly sampled (without replacement) set number of observations (40): 

y<-data[sample(1:nrow(data),40,replace=FALSE),] 

I would like to make a new variable "x" that contains the 
leftover non-sampled 110 observations.  I am sure there is a fairly easy
 way to do this. 

Any help would be greatly appreciated. 

THANKS!



More information about the R-help mailing list