全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1427 1
2018-12-30
temp=rep(c(300,500,750,800),c(5,5,5,5))
rst=c(90,92,88,89,92,95,92,88,89,92,96,96,97,94,92,91,90,93,89,88)
temp_factor=factor(temp)
df=data.frame(rst,temp_factor)
aov(rst~temp_factor,df)
Call:
   aov(formula = rst ~ temp_factor, data = df)
Terms:
                temp_factor Residuals
Sum of Squares        78.15     74.40
Deg. of Freedom           3        16

这是正确的。而以下是错误的,这是为什么
temp=rep(c(300,500,750,800),c(5,5,5,5))
rst=c(90,92,88,89,92,95,92,88,89,92,96,96,97,94,92,91,90,93,89,88)
temp_factor=factor(temp)
df=data.frame(cbind(rst,temp_factor))
aov(rst~temp_factor,df)
为什么加上了一句,cbind之后就变成了。。
Call:
   aov(formula = rst ~ temp_factor, data = df)
Terms:
                temp_factor Residuals
Sum of Squares         3.61    148.94
Deg. of Freedom           1        18
Residual standard error: 2.876533




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2018-12-30 21:39:13
在cbind的帮助说明中有这么一句“The type of a matrix result determined from the highest type of any of the inputs in the hierarchy raw < logical < integer < double < complex < character < list .”

在本例中
复制代码


所以在使用cbind后,temp_factor已经不是因子了,它被转换成了double
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群