Reputation: 3441
Lets say I have these data:
set.seed(123)
data <- data.frame(IndID = rep(c("AAA", "BBB", "CCC", "DDD", "EEE"),10),
ValueOne = rnorm(50),
ValueTwo = rnorm(50))
head(data)
Where there are 50 observations of two different values from 5 individuals (AAA - EEE).
I want to subset the example data to exclude Inds "AAA","BBB"and "EEE" and have named them to an new object.
RemoveInds <- c("AAA","BBB","EEE")
How would I create a new data.frame
that excludes these individuals and does so using the object RemoveInds
?
What am I missing here?
newData <- data[data$IndID != RemoveInds,]
newData <- subset[data, data$IndID != RemoveInds]
Thanks in advance.
Upvotes: 0
Views: 185
Reputation: 7796
Does this do what you're looking for?
newdata<- data[!data$IndID %in% RemoveInds, ]
Upvotes: 2