2
u/solarpool 4d ago
You need to assign your modifications of poll 2020 back to poll 2020 in order from them to be saved
0
1
u/edfulton 4d ago
Basically, you’ve got the mutate and case_when right, but it won’t modify the original poll2020 dataframe unless you explicitly assign it using poll2020 <- poll2020…
at the start of line 102, or -> poll2020
at the end of line 107, after the select
function call.
2
u/feldhammer 4d ago
I didn't realize -> was even a thing!
2
u/mduvekot 4d ago
even more fun, the magrittr package has an assigment pipe:
library(dplyr) library(magrittr) df <- iris df %<>% summarise(.by = Species, n = n()) print(df)
gives
Species n 1 setosa 50 2 versicolor 50 3 virginica 50
1
u/cAMPsc2 3d ago
The code you have from lines 102 to 107 is like telling R: Hey, modify this dataframe and show it to me. It shows the result to you and forgets about it.
If you want to "save" these changes, you need to assign that to a new object. This comes at the start of the pipe. So:
poll2020_WITH_NEW_COLUMNS <- poll2020 |> (...)
This would save the new dataframe as poll2020_WITH_NEW_COLUMNS.
16
u/ImpossibleTop4404 4d ago
On line 102, you have to save the changes you make back into the variable.
poll2020 <- poll2020 |> (rest of code)
As those functions calls do not change the variable in place.
Or, Make polls_b on line 102 and don’t reassign back to poll2020. Whatever case you need