how to get average value from two columns of data table using dplyr? For example, if my data, for example, is lower:
dt <- data.table(A=1:5, B=c(1,4,NA,6,8))
I want to create a new column "Avg", which is the average for columns A and B for each row:
dt %>% mutate(Avg=mean(c(A, B), na.rm=T))
But this code does not give me the correct result. How to do it? Thank you very much.
source share