Hello, I have been trying to write a small program to generate automatic plots. What I want is to draw boxplots for some variables in my data frame, contrasting with a variable called 'missing' that has value 1 if some variable in a concrete case has at least one missing value, in order to check if the cases that don't enter in my analysis are biased. The first attempt was to start generating a list with the variables of contrast and then apply the list to the plots:> varlist <- c("var1", "var2", "var3", "var4", ...)> for (i in 1:length(varlist)) {+ jpeg("varlist[i].jpg", width=480, heigth=480) + boxplot (varlist[i] ~ missing, xlab="missing values", ylab="varlist[i]) + } But I got 'Error in model.frame(formula, rownames, variables, varnames, extranames: invalid variable type' I suppose that is because I forget something related to the extraction of values in vectors, but I can't find it on the R manual neither in other books about R that I have checked. Is there a way to draw plots using commands like the one above? Thanks, Xavier
Xavier Fern?ndez i Mar?n wrote: ...>>varlist <- c("var1", "var2", "var3", "var4", ...)Instead of a character vector with the names, it'd make life easier if you had a list of the vectors... # make sure you use the naming - makes life easier later. mylist <- list(var1=var1, var2=var2, var3=var3, var4=var4) Then... for(i in seq(along=mylist)) { # seq(along=...) is safest. jpeg(names(mylist)[i], width=...) boxplot(mylist[[i]] ~ missing, xlab=...) dev.off() # you didn't have this. it's required. } # but I don't see how "missing" gets correctly passed in your example, # so I'm not sure what it's supposed to do.> I suppose that is because I forget something related to the extraction of > values in vectors, but I can't find it on the R manual neither in other books > about R that I have checked.Nope. It's about passing a strings of text to plot, instead of actual data. You'd have to actually parse the string to produce the value. And that's getting tricky (at least, it's tricky to my brain). The above is pretty simple by comparison. Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 jasont at indigoindustrial.co.nz
On Wednesday 08 October 2003 12:05, Xavier Fern?ndez i Mar?n wrote:> Hello, > > I have been trying to write a small program to generate automatic > plots. What I want is to draw boxplots for some variables in my data > frame, contrasting with a variable called 'missing' that has value 1 > if some variable in a concrete case has at least one missing value, > in order to check if the cases that don't enter in my analysis are > biased. > > The first attempt was to start generating a list with the variables > of > > contrast and then apply the list to the plots: > > varlist <- c("var1", "var2", "var3", "var4", ...) > > > > for (i in 1:length(varlist)) { > > + jpeg("varlist[i].jpg", width=480, heigth=480)here you want paste(varlist[i], ".jpg", sep = "")> + boxplot (varlist[i] ~ missing, xlab="missing values",and here mydataframe[, varlist[i]] ~ missing hth, Z> ylab="varlist[i]) + } > > But I got 'Error in model.frame(formula, rownames, variables, > varnames, extranames: invalid variable type' > > I suppose that is because I forget something related to the > extraction of values in vectors, but I can't find it on the R manual > neither in other books about R that I have checked. > > Is there a way to draw plots using commands like the one above? > > Thanks, > > > Xavier > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help