I have a data frame ("tidydataset") that looks like this:
Block Group_code avg count
1 Q.DB1_01 1.53 456
1 Q.DB1_02 1.63 456
1 Q.DB1_03 1.29 456
1 Q.DB2_01 2.11 456
1 Q.DB2_02 1.43 456
1 Q.DB2_03 1.61 456
I am trying to create a new variable that takes the 5th character of "Group_code" and then recodes it according to the following levels: 1 = Phone, 2 = Tablet, 3 = PC, etc.
This is my code so far:
tidydataset %>%
mutate(Group_name = as.numeric(substr(Group_code, start=5, stop=5))) %>%
mutate(Group_name = recode(Group_name, `1` = "Phone", `2` = "Tablet", `3` =
"PC"))
This throws up an error message: "Error in mutate_impl(.data,dots) : Evaluation error: unused arguments (1 = "Phone", 2 = "Tablet", 3 = "PC").
Any idea where I'm going wrong? ALso is there any way to combine those two mutate statements into one, and write the new column to the data frame?
Thanks
Group_namecolumn. - AntoniosK