r - Transferring information from a dataframe to another -
here problem. have 2 dataframes, df1 , df2. i'd add column named issp df1 in function of values taken column named sp in df2. df1 , df2 have column named loc in common repeated lot in df2 (~90k rows in df2 against 5k rows in df1).
the idea identify locations in df1 contain specie sp giving column issp value 1.
here script use:
for (i in (1:length(df2$loc)) { if (df2[i, "sp"]==1) { df1(which[df1$loc==df2[i, "loc"]],)$issp = 1 } } it doesn't work , r sends me following error:
error in `*tmp*`[df1[, "loc"] == df2[i, "loc"]] : object of type 'closure' not subsettable`
you have syntax error:
df1(which[df1$loc==df2[i, "loc"]],)$issp = 1 should be
df1[which(df1$loc==df2[i, "loc"]),]$issp = 1
Comments
Post a Comment