recover rows from a data frame

Asked

Viewed 31 times

0

I need to recover the entire line of the DF, in a new DF, only when I find the vector element, in the id field of the DF

ids <- c(2001586,2007037,2012677,2020645)

df <- t(data.frame(colnames = c("ID", "A", "B", "C", "D", "E"),
"1" = c(2002043, 3, 04, 01, 01, 03),
"2" = c(2002159, 3, 04, 01, 01),
"3" = c(3006166, 3, 04, 03, 02, 03),
"4" = c(3006166, 3, 04, 03, 02, 03),
"5" = c(3518655, 3, 04, 01, 69, 03),
"6" = c(3518655, 3, 04, 01, 69, 03),
"7" = c(3518655, 3, 04, 01, 69, 03),
"8" = c(3968308, 1, 04, 01, 39, 03),
"9" = c(5215625, 1, 04, 01, 39, 03),
"10" = c(6249256, 3, 04, 03, 39, 03),
"11" = c(2001586, 1, 01, 03, 05, 04),
"12" = c(2001586, 1, 01, 03, 05, 04),
"13" = c(2001586, 1, 01, 03, 05, 04),
"14" = c(2000865, 3, 04, 03, 05, 06),
"15" = c(2000865, 3, 04, 03, 05, 06),
"16" = c(2000873, 3, 04, 03, 02, 03),
stringsAsFactors = FALSE))

this function only returns me an id of the DF
result <- as.data.frame(lapply(df[1], Function(x) Intersect(ids,x)))

How can I do that?

1 answer

0

result <- df[df[1]==(lapply(df[1], Function(x) Intersect(ids,x))),]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.