2017-04-11 126 views
0

這是我的R上的代碼,它不斷讓我的消息錯誤:意外「}」在「}」在一個循環內循環(而功能)

Error: unexpected '}' 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

你可以提供一些示例數據,以便我們可以真正運行它嗎? – eckes

+3

'filter'命令中的'&'是個問題。只用'過濾器(groupe = i)'一切正常。你的意思是'filter(groupe = c(i,n))'? –

+0

真棒,這是問題!你搖滾隊友:D –

回答

0

&中的filter命令是問題所在。只要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 
}