Dear R users; I am trying to combine 2 dataframes with different rows, 26 and 6 rows. The first column of both dataframe has something in common, and I want to compare the first column of the df1 with first column of the df2 to see if they are same or not. Then if they were same, the second column of the df1 fill by the value of the second column of df2.
df1 = data.frame(x1 = letters[1:26],x2 = NA) df2 = data.frame(x1 = letters[10:15],x2 = c("1a","2a","3a","4a","5a","6a")) f = function(x,y){ for (i in 1:nrow(df1)) ifelse(df1$x1 == df2$x1, df1$x2==df2$x2, "NA")} f(df1,df2) Error in Ops.factor(df1$x1, df2$x1) : level sets of factors are different Is there anyone to help me to solve this problem? Sincerely. -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat...@yahoo.com [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.