Hi I'm new to R an have my first problem,
I have basically a data structure that looks pretty similar to:
ID <- c(1,2,3)
C <- c(0.4,0.4,0.2)
B <- c(0.4,0.3,0.2)
A <- c(0.2,0.3,0.6)
df <- data.frame(ID,A,B,C)
head(df)
ID A B C
1 1 0.2 0.4 0.4
2 2 0.3 0.3 0.4
3 3 0.6 0.2 0.2
where A,B,C correspond to grades A=1,B=2,C=3
I would like to compute the weighted average column for each row like:
ID 1 A*0.2 + B*0.4 + C*0.4
...
I tried:
as.numeric(as.character(names(df[,2:ncol(df)]))) * df[2:nrow(df),]
But that seems not right.