Below is my R code, but I couldn't decipher the "result" part. It doesn't work the way I want (see the Excel image below).
library(tidyverse)
Question_No <-c(1,1,1,1,1,10,10,10,10,10,11,11,11,11,11)
Reply<-c("never","few","medium","much","complete",
"never","few","medium","much","complete",
"never","few","medium","much","complete")
Number_of_Answers<- c(7,1,12,13,18,6,2,12,10,21,6,2,13,11,19)
aa<- data.frame(Question_No,Reply,Number_of_Answers)
replace<- function(x)
{Replys=x['Reply']
if(Replys=="few"){return(2)}
else if(Replys=="much"){return(4)}
else if(Replys=="never"){return(1)}
else if(Replys=="medium"){return(3)}
else {return(5)}}
Replys<- apply(aa,MARGIN = 1,FUN = replace)
aa['Replys']<-Replys
aa= mutate(aa,NA_R = aa$Replys * aa$Number_of_Answers)
aa$result = ifelse(aa$Question_No==1, sum(aa$NA_R) ,"n")
View(aa)
My aim is to use R to reproduce the result in EXCEL shown in the picture below.
Thank you for the help.