[R] Problem with combining 2 data frame

javad bayat j@b@y@t194 @end|ng |rom gm@||@com
Fri Feb 15 18:24:53 CET 2019


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: bayat194 using yahoo.com

	[[alternative HTML version deleted]]



More information about the R-help mailing list