內我有一個數據幀,看起來像這樣:對象在case_when未找到管
gov1rlc gov2rlc gov3rlc gov1vote gov2vote gov3vote
<int> <int> <int> <dbl> <dbl> <dbl>
3 2 NA 24.35 1.04 0
2 3 2 NA 24.35 1.04
3 2 NA 24.35 1.04 0
3 NA NA 54.40 0.00 0
3 NA NA 54.40 0.00 0
3 NA NA 54.40 0.00 0
在這一點上,我想計算左翼政黨(gov1rlc,gov2rlc的選票份額,gov3rlc等於3 ),對於我使用下面的代碼:
d <- d %>% mutate(left_share=case_when(gov1rlc==3&gov2rlc==3&gov3rlc==3~gov1vote+gov2vote+gov3vote,
gov1rlc==3&gov2rlc==3&gov3rlc!=3~gov1vote+gov2vote,
gov1rlc==3&gov2rlc!=3&gov3rlc==3~gov1vote+gov3vote,
gov1rlc==3&gov2rlc!=3&gov3rlc!=3~gov1vote,
gov1rlc!=3&gov2rlc!=3&gov3rlc!=3~0,
gov1rlc!=3&gov2rlc==3&gov3rlc==3~gov2vote+gov3vote,
gov1rlc!=3&gov2rlc==3&gov3rlc!=3~gov2vote,
gov1rlc!=3&gov2rlc!=3&gov3rlc==3~gov3vote))`
不過,後來我得到Error in mutate_impl(.data, dots) : object 'gov1rlc' not found
,這是非常奇怪的考慮,我在管,而相同的代碼在另一臺計算機上工作。
如果我在每個對象之前使用d$
運算符,則會顯示以下消息:Error in mutate_impl(.data, dots) : NAs are not allowed in subscripted assignments
。
簡單地說:發生了什麼,發生了什麼?
聽起來就像你使用的是舊版本的dplyr。更新應該解決這個問題。 –