I have two data frames. The first looks like this:
value <- seq(1, 100, length.out=20)
df1 <- data.frame(id=as.character(1:20),
value=value,
stringsAsFactors=F)
I have a second dataframe that looks like this
df2 <- data.frame(id=as.character(c(1:5, 21:23)),
v2=NA,
stringsAsFactors=F)
I need the values transferring from df1
to df2
, but only where df1$id == df2$id
. So the dataframe I need is:
df2Needed <- data.frame(id=as.character(c(1:5, 21:23)),
v2=c(value[1:5], NA, NA, NA),
stringsAsFactors=F)
Is there a way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…