Dear all, I am a new R user, and I have a question about R macro.
Here is the situation, I want to do item option analysis (options include: A , B, C, D), below is the codes for option A analyses. #option A analyses optiona<-mat.or.vec(nrow(responsedata2), ncol(responsedata2)) # create A matrix by recoding for (i in 1:ncol(responsedata2)){ optiona[,i]<-recode(responsedata2[,i],"'A'=1;NA=NA;else=0") } # compute mean for A matrix pa<-rep(0,ncol(optiona)) for (i in 1:ncol(optiona)){ pa[i]<-round(mean(optiona[,i],na.rm=TRUE),2) } pa1<-as.data.frame(pa) I can repeat the codes for other options such as "B", "C" and "D", but I am wondering if I can do it in a macro way--subsituting "A" "a" in the codes with "B" "b", etc. In SAS it can be done easily, but I could not get it to work in R. Waiting for your reply. And thank you so much in advance. Meng [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.