[R] Excluding observations

arun smartpink111 at yahoo.com
Sun Apr 21 16:32:55 CEST 2013


Hi Farnoosh,
set.seed(25)
Data.All.Var<- data.frame(ID= sample(LETTERS[1:10],25,replace=TRUE), value=rnorm(25),stringsAsFactors=FALSE)

set.seed(28)
Y.Out<- data.frame(ID=sample(LETTERS[1:5],25,replace=TRUE),value=rnorm(25),stringsAsFactors=FALSE)
unique(Y.Out$ID)
#[1] "A" "C" "E" "D" "B"
 unique(Data.All.Var$ID)
# [1] "E" "G" "B" "I" "J" "D" "A" "C" "F" "H"
 Data.All.Var$ID[!Data.All.Var$ID%in% Y.Out$ID]
 #[1] "G" "I" "J" "G" "J" "F" "G" "F" "H" "H"
DataAllExclude<- Data.All.Var[!Data.All.Var$ID%in% Y.Out$ID,]
 DataAllExclude
#   ID       value
#2   G  0.23508558
#4   I -0.38736217
#6   J -0.24331815
#7   G -0.32137638
#13  J  0.57385268
#14  F  0.59750664
#15  G -0.01775669
#17  F  0.11683731
#18  H -1.11311883
#20  H  0.46184261
A.K.




________________________________
 From: farnoosh sheikhi <farnoosh_81 at yahoo.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
Sent: Sunday, April 21, 2013 2:45 AM
Subject: Excluding observations
 


Hi Arun,

I have a bit problem excluding some observations from the ID variable in the data.
I really appreciate if you can help me.

The values that I want to exclude are coming from: 

inter<-Data.All.Var$ID[Data.All.Var$ID%in%Y.Out$ID]
inter<- as.character(inter)


Exclude from the original data:
DataAllExclude<-Data.All.Var$ID[-inter] or [!inter] ----> this code doesn't work!


Thanks a lot.



More information about the R-help mailing list