Thank you very much in advance!
If you already have a column with the number of NA responses per row, you can divide the value in the column by the number of columns that contain responses to questions. In the following simple example, I use the ncol() function to count the total number of columns and subtract two from that to account for the columns named Person and Count_NA that do not represent questions.
Is that what you need?
DF <- data.frame(Person = c("A", "B", "C"),
Q1 = c(1:3),
Q2 = c("X", NA, "Z"),
Q3 = c(NA, NA, "Yes"),
Count_NA = c(1,2,0))
DF
#> Person Q1 Q2 Q3 Count_NA
#> 1 A 1 X <NA> 1
#> 2 B 2 <NA> <NA> 2
#> 3 C 3 Z Yes 0
DF$Frac_NA = DF$Count_NA/(ncol(DF) - 2)
DF
#> Person Q1 Q2 Q3 Count_NA Frac_NA
#> 1 A 1 X <NA> 1 0.3333333
#> 2 B 2 <NA> <NA> 2 0.6666667
#> 3 C 3 Z Yes 0 0.0000000
Created on 2022-07-26 by the reprex package (v2.0.1)
1 Like
Thank you so much! That really helped me a lot!!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.