How can you summarize multiple columns together that have nominal variables in R

Viewed 24

I have a data frame where I'm trying to summarize multiple columns together. These columns all show a type of contact as a nominal variable (Phone, letter, email, in-person) and I have a column for each contact attempt. I'd like to sum all the times a person was called, mailed a letter, emailed, or visited in person for all the rows.

So far I've tried creating a dummy variable for each of the variable types:

    contact=contact %>% 
  mutate(contact_phone_1 = if_else(contact$rec_contact_type_1=="Phone", "1", "0",))

contact=contact %>% 
  mutate(contact_phone_2 = if_else(contact$rec_contact_type_2=="Phone", "1", "0",))

df$col1 <- as.numeric(df$contact_phone_1)
df$col2 <- as.numeric(df$contact_phone_2)

That created a total of things, but it's messy.

I also tried doing summarize_at(var(df$contact_phone_1,df$contact_phone_2)), but that had some significant errors. I'm rusty with R and am feeling stuck. Any assistance would be appreciated

0 Answers
Related