I have a data frame with the first column as a categorical identifier, the second column as a frequency value, and the remaining columns as raw data. I want to multiply all count columns by frequency columns, but not the first two.
All raw count columns start with an uppercase letter followed by a full stop, such as "L.abd", T.xyz, etc.
For example, if I use the code:
require(dplyr) ID <- c(1,2,3,4,5,6) Freq <- c(0.1,0.2,0.3,0.5,0.1,0.3) L.abc <- c(1,1,1,3,1,0) L.ABC <- c(0,3,2,4,1,1) T.xyz <- c(1,1,1,1,0,1) F.ABC <- c(4,5,6,5,3,1) df <- as.data.frame(cbind(ID, Freq, L.abc, L.ABC, T.xyz, F.ABC)) df_new <- df %>% mutate_each(funs(.*Freq), starts_with("L."))
I can create a new data frame containing columns of categorical data, along with those columns starting with "L." which were multiplied by the corresponding frequency value.
Is there a way to change the start_with command to select all columns starting with a capital letter and stop completely? My attempts to use modifications such as "[AZ]". were unsuccessful.
Thank you in advance