我有一个数据框,包含165个变量的1447个障碍,我希望通过处理现有的列来添加列。我有:
resvar <- 111
# column number of response variable (e.g. CPUE) in "samples" (the data frame)
我希望log1p将该列111逐行地添加到一个名为&#34; grv&#34;的新列中。在样本结束时:
samples$grv <- log1p(samples[resvar])
但它将输出放入列grv,第1行,作为``c(item1,item2,... item1447)`
class(log1p(samples[resvar])) = data.frame
有谁知道发生了什么&amp;为什么它不起作用? 如果我做
dummy <- log1p(samples[resvar])
dummy
是一个data.frame,其行名与resvar,第111列的行名称中的行名相同。这是问题吗?
答案 0 :(得分:0)
samples$grv <- log1p(samples[,resvar])
或samples$grv <- log1p(samples[[resva]])