Transfer values from one dataframe to another

后端 未结 4 804
醉梦人生
醉梦人生 2020-12-16 05:13

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), 
                  valu         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 05:35

    Just adding another approach to the existing list of excellent answers:

    > library(dplyr)
    > library(qdapTools)
    > mutate(df2, v2 = id %l% df1)
    #  id        v2
    #1  1  1.000000
    #2  2  6.210526
    #3  3 11.421053
    #4  4 16.631579
    #5  5 21.842105
    #6 21        NA
    #7 22        NA
    #8 23        NA
    

提交回复
热议问题