I have a dataset like below. I want to create the score variable with code.
Calculation of the score; Total of the entire row / Number of full columns
For example, the score calculation for row 1: (1+2+1) / 3 = 1.33
For example, the score calculation for row 2: (1+1) / 2 = 1
df <- data.frame(
X1 = c(1,1,2,3,NA),
X2 = c(2,1,NA,2,2),
X3 = c(1,NA,2,2,1),
Skor=c(1.33,1,2,2.33,1.5)
)
df
> df
X1 X2 X3 Skor
1 1 2 1 1.33
2 1 1 NA 1.00
3 2 NA 2 2.00
4 3 2 2 2.33
5 NA 2 1 1.50
>