(d)plyr中的mutate()在采购时不会创建新列 [英] mutate() in (d)plyr does not create new column when sourced
本文介绍了(d)plyr中的mutate()在采购时不会创建新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
source(dply_problem.R)
调用到以下代码 library(dplyr)
df< - data.frame(A= 1:6,
B= 7:12)
mutate df,C = A + B)
列C不会添加到 DF
。但是,当我从shell调用 mutate(df,C = A + B)
时,会创建列C。你能给我一个提示,为什么会发生这种情况?
解决方案
你没有将输出分配给任何东西。尝试:
库(dplyr)
df< - data.frame(A = 1:6,
B= 7:12)
df< - mutate(df,C = A + B)
df
I am using the package dplyr with R (same problem applies to plyr, too). When I call source("dply_problem.R")
to the following code
library("dplyr")
df <- data.frame("A" = 1:6,
"B" = 7:12)
mutate(df, C = A + B)
the column "C" does not get added to df
. However, when I call mutate(df, C = A + B)
from the shell, the column "C" does get created. Could you give me a hint why this is happening?
解决方案
You haven't assigned the output to anything. Try:
library("dplyr")
df <- data.frame("A" = 1:6,
"B" = 7:12)
df <- mutate(df, C = A + B)
df
这篇关于(d)plyr中的mutate()在采购时不会创建新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文