I want to plot similar figures by using a list of variables.
The list of variables are "wuc_above, parti_above, "see_above", "look_above". All these variables are dummies(i.e, they equal to either 0 or 1)
The code to plot the figures are:
pdf(file ="mypath/wuc_above.pdf")
boxplot(x1[wuc_above==1] ,x2[wuc_above==1])
dev.off()
}
I want to replace the variable "wuc_above" by "parti_above", "see_above", "look_above". x1, x2 are some numeric variables that scale from 0 to 7.
It works like the Stata global function. However, I didn't figure out how to achieve this in R. Could anyone help me? Thanks!
I've written sth like (of course this does not work...)
varlist <- variable.names(wuc_above,parti_above)
for (i in varlist) {
pdf(file =paste0('"mypath/',i,'.pdf'"))
boxplot(x1[paste0(i)==1] ,x2[paste0(i)==1])
dev.off()
}