First of all I would advice you to use meaningful subjects when posting to the list.

My second point is only a vague guess, but if you use the exact code that you posted there may be bracket missing....(its the closing bracket of the jpg() call ). May this produce your error?

Third, you should use [[]] instead of $ to access the elements of the data frame ( see ?$ ). blith[[item]] should do the job.


HTH
Jannis

On 02/14/2011 07:33 AM, Smith, Taylor Taran wrote:
Hey,

I am trying to graph a series of XY plots from a set of .csv files. Getting the 
csv files read in and the original plot set up is not a problem, but I cannot 
figure out a way to call get(iterator) within a separate dataset. A chunk of my 
code is below.


data<- read.csv(file= filename)
data2<- read.csv(file= filename2)

names<- names(data)
attach(data)

for (item in names) {
     jpeg(filename=sprintf(directory_%s.jpg, item)
     plot(SiO2, get(item), pch="", ylab=sprintf("%s", item))
     points(alith$SiO2, alith$get(item), pch=21, col="red")
     points(blith$SiO2, blith$get(item), pch=21, col="blue")
     points(clith$SiO2, clith$get(item), pch=21, col="green")
     points(dlith$SiO2, dlith$get(item), pch=21, col="orange")
     points(glith$SiO2, glith$get(item), pch=21, col="red4")
     points(hlith$SiO2, hlith$get(item), pch=21, col="purple")
     points(llith$SiO2, llith$get(item), pch=21)
     dev.off()
}

Ideally this would spit out hundreds of xy plots (and it does work if I plot them all in 
the same color by turning the pch="" off. However, when calling from a dataset 
with $, it will not let you use a function as the argument (the get(item) part gives an 
error). Is there any way around this?

Thanks

Taylor

______________________________________________
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.


______________________________________________
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.

Reply via email to