我的问题是指在 Dplyr 中循环。我正在尝试确定自变量(IV1:IV5)的每个独特组合的 DV1 的平均值、计数和方差。我的数据如下所示:
DV1 IV1 IV2 IV3 IV4 IV5
506.2 Male Canada alpha low Orange
418.7 Female Canada beta mid Orange
380.3 Male Canada alpha high Red
347.3 Male Canada alpha mid Red
241.6 Female UStates alpha mid Blue
223.7 Female Canada beta low Green
220.9 Male Canada alpha low Orange
201.1 Male Canada alpha low Red
193.8 Female Canada beta mid Green
179.7 Female UStates beta low Orange
170.7 Male UStates beta mid Blue
149.5 Male UStates beta low Green
146.2 Male Canada beta high Green
144.2 Female UStates beta mid Red
141.5 Male Canada beta high Blue
138.6 Male Canada beta mid Blue
137 Male Canada beta low Red
136 Female UStates beta mid Orange
135.9 Female UStates beta low Red
134.6 Male UStates alpha mid Orange
129 Female UStates beta mid Green
127.1 Female UStates beta low Green
120.4 Male UStates beta low Blue
119.3 Female UStates beta high Red
118.6 Female Canada alpha low Blue
116.2 Female Canada alpha high Green
113.7 Male UStates beta high Green
112.9 Female UStates beta low Green
112.6 Male Canada alpha mid Green
112.2 Male Canada alpha mid Orange
109 Female Canada beta high Orange
108.1 Female Canada alpha mid Blue
99.1 Female Canada alpha high Blue
95.6 Male UStates beta mid Green
88.1 Male Canada alpha high Blue
83.9 Female Canada beta high Green
83.7 Male Canada alpha low Green
80.8 Male Canada alpha high Orange
79.9 Female UStates alpha high Blue
78 Female UStates alpha mid Red
76.3 Female UStates alpha low Blue
74.1 Female UStates beta high Orange
65.7 Female UStates beta high Red
62.1 Male UStates alpha high Red
54.8 Male Canada beta low Blue
54 Male UStates alpha mid Red
42.8 Female UStates alpha low Red
39.6 Male UStates alpha high Orange
19.5 Male UStates alpha low Orange
19.2 Female Canada alpha mid Green
使用 Dplyr,我已经能够创建它。我需要 IV1:IV5 的每个独特组合的描述性统计信息下可用的信息
mod1=data1 %>%
group_by(IV1)%>%
summarise(avg_banding=mean(DV1),
total.count=n(),
variance=var(DV1)) %>%
print(n=50)
#Descriptive statistics for the entire group (required!)
sum(mod1$avg_banding)
mean(mod1$avg_banding)
mean(mod1$total.count)
mod1_2=mod1[complete.cases(mod1),]
sum(mod1_2$variance)
正如您可能会说的那样,我必须对每种可能的组合都这样做......(IV1)(IV1,IV2)(IV1,IV2,IV3)(IV2,IV3)等。有很多组合,我想知道是否有一种更简单的方法可以做到这一点,而不是为每个人都插上电源!我尝试使用 for 循环但没有成功。
mod2=data1 %>%
group_by(IV2)%>%
summarise(avg_banding=mean(DV1),
total.count=n(),
variance=var(DV1)) %>%
print(n=50)
sum(mod2$avg_banding)
mean(mod2$avg_banding)
mean(mod2$total.count)
mod2_2=mod2[complete.cases(mod2),]
sum(mod2_2$variance)
非常感谢任何帮助!谢谢!