user3294511 user3294511 - 1 month ago 14
R Question

Error with subset

I have a

data.frame
which I want to subset based on a list of certain IDs. I want to extract all the rows from this
data.frame
which have the same ID as my variable "genes". So far I have:

Final_Genes <- subset(Merged_Results,Merged_Results$Entrez.ID == genes, select = c(1:8))


but this produces an error,

Warning messages:

1: In is.na(e1) | is.na(e2) :
longer object length is not a multiple of shorter object length
2: In `==.default`(Merged_Results$Entrez.ID, genes) :
longer object length is not a multiple of shorter object length


Which to be honest I don't understand.

Answer

Try

Final_Genes<-Merged_Results[Merged_Results$Entrez.ID==genes,1:8]

This assumes that "genes" is that same as a single Entrez.ID. If genes is acutally a vector of several "Entrez.ID"s you could replace the == with %in%