In SAS, this would be:
newvariable=mean(of x1, x2, x3, x4);
Stockoverflow
R
Approach 1:
x2 <-subset(time1data,select=c(x1, x2, x3, x4, x5))
time1data$newvar<-rowMeans(x2,na.rm=TRUE)
Approach 2
time1data$newvar<-rowMeans(time1data[,c("q0008_0001", "q0008_0002", "q0008_0003", "q0008_0004", "q0008_0005", "q0008_0006", "q0008_0007", "q0008_0008")])
Approach 3
time1data$newvar<-rowMeans(time1data[,c("q0008_0001", "q0008_0002", "q0008_0003", "q0008_0004", "q0008_0005", "q0008_0006", "q0008_0007", "q0008_0008")],na.rm=TRUE)