错误:意外'}' in" }"循环中的循环(同时函数)

时间:2017-04-11 11:24:30

标签: r loops while-loop

这是我在R上的代码,它不断给我留言

  

错误:意外'}' in" }"

当我尝试运行它时。问题是什么?我检查了括号的余额,并根据论坛它应该工作。

n = 1 
while(n < 3) { 
    i = 2
    while (i < 17) {
        data_freq = data_pourcentage %>%
            filter(groupe = i & groupe = n) %>%
            mutate(pourcentage = sum(freq)) %>%
            mutate(pourcentage = freq / pourcentage)
        data_pourcentage = left_join(
            data_freq, 
            data_pourcentage, 
            by = c(
                "sujet", "groupe", "identification", 
                "cristallisation", "valence", "freq")
            )
        i = i + 1
    }
    n = n + 1
}

1 个答案:

答案 0 :(得分:0)

过滤器命令中的&是问题所在。只需filter(groupe = i),一切正常。要合并更多组件,请使用filter(groupe= c(i,n))

n = 1 
while(n < 3) { 
    i = 2
    while (i < 17) {
        data_freq = data_pourcentage %>%
            filter(groupe = c(i,n)) %>%
            mutate(pourcentage = sum(freq)) %>%
            mutate(pourcentage = freq / pourcentage)
        data_pourcentage = left_join(
            data_freq, 
            data_pourcentage, 
            by = c("sujet", "groupe", "identification", 
                   "cristallisation", "valence", "freq")
            )
        i = i + 1
    }
    n = n + 1
}