I'm new to R and I've been doing ok so far but I need to do something a little complicated now and can't quite get it to work. I have a dataset similar to the following (going forward I will call this df):
df <- tribble(~name, ~word, ~N,
"brandon", "hello", 3,
"john", "test", 5,
"jim", "hello", 2,
"brandon", "goodbye", 2,
"brandon", "test", 1,
"jim", "goodbye", 4)
so far I have something like this going on:
temp_df <- df %>% mutate(
"hello" = ifelse(word == "hello", N, 0),
"goodbye" = ifelse(word == "goodbye", N, 0),
"test" = ifelse(word == "test", N, 0)
)
which is creating something like this:
name hello goodbye test word N
brandon 3 0 0 hello 3
john 0 0 5 test 5
jim 2 0 0 hello 2
brandon 0 2 0 goodbye 2
brandon 0 0 1 test 1
jim 0 4 0 goodbye 4
but I need the df to look like this:
name hello goodbye test
brandon 3 2 1
john 0 0 5
jim 2 4 0
I know how to select() the important data once I'm done here but I'm just not sure how to get all the data for each name into one row.