在bear
中使用R
包时出现以下问题:
origdata.wide <- read.table(header=T, text='
subject sex control cond1 cond2
1 M 7.9 12.3 10.7
2 F 6.3 10.6 11.1
3 F 9.5 13.1 13.8
4 M 11.5 13.4 12.9
')
如果我只使用reshape2
,此命令可以正常工作,我可以使用melt
(取自R Cookbook的示例)。
library(reshape2)
melt(origdata.wide, id.vars=c("subject","sex"), variable.name='Condition')
但后来我需要使用summarySE
函数,我发现它包含在bear
中。我的问题是,当我加载bear
时,variable.name
参数没有任何影响,我也无法定义我之前定义的表。所以我认为bear
会覆盖一些功能。有没有解决这个问题的方法?
答案 0 :(得分:1)
您可以通过命名空间melt
访问函数reshape2
,即
reshape2::melt(....)
答案 1 :(得分:0)
如果有任何事情被覆盖,R会通知您。例如:
The following objects are masked from ‘package:plyr’:
rename, round_any
似乎bear
加载了reshape
包,它将具有与这些函数不同的参数:
The following objects are masked from ‘package:reshape’:
colsplit, melt, recast
您可以通过手动重新加载来解决您的问题,并且将来要小心按以下顺序加载包:
unloadNamespace('bear')
unloadNamespace('reshape2')
library(bear)
library(reshape2)
如果您发现表单有任何错误
Error in unloadNamespace("reshape2") :
namespace ‘reshape2’ is imported by ‘ggplot2’ so cannot be unloaded
然后unloadNamespace
这些包,然后重新加载它们。在~/.Rprofile
文件中,您可以放置
library(bear)
library(reshape2)
以便将来正确加载新的R会话。