R - for value in dataframe, create a new dataframe with the value -


i'm having issue referencing df filter out values in df hold in new df.

an example:

df1 <- c("a", "b", "c", "d") value <- c(1, 2, 3, 4) df1 <- as.data.frame(cbind(df1, value)) names(df1) <- c("id", "value")  df2 <- c("a", "b") names(df2) <- c("id") 

what see final dataset this:

id   value    1 b    2 

i'm not sure if loop or use of %in% operator , appreciated...

in case, try:

output <- df1[df1$id %in% c("a","b"),]

for more generalised cases:

match_ids <- c("a","b","another id","yet id") output <- df[df$id %in% match_ids] 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -