0

I have two dataframes, dataframe 1 has multiple repeating values, dataframe 2 indicates the category of these values. I would like to add this category for all my values in dateframe 1 in an additional column, something like if(df1[i,1] = df2[,1]) {df1[i,2] = df2[,2]}. For example, if df1[i,1] = 2 and in df2, 2 & "b" are in the same row: df1[i,2] = "b" for all rows in df1 with 2 in its first column.

Here's a small SRS to fiddle with.

set.seed(123)
df1 <- data.frame("v"= sample(1:3, size = 10, replace=T), "category"=rep("",10))
df2 <- data.frame("v"= 1:3,"c"= c("a","b", "c"))

#    v category
# 1  3         
# 2  3         
# 3  3         
# 4  2         
# 5  3         
# 6  2         
# 7  2         
# 8  2         
# 9  3         
# 10 1  

0 Answers0