[R] Subset and plot

Jeff Laake Jeff.Laake at noaa.gov
Tue Feb 2 23:05:01 CET 2010

The problem is with attach.  You should have seen an error that the 
objects are aliased.  You have Tanks in your workspace and in the 
attached dataframe. It is using the one in your workspace which is not a 
factor variable.  Try:


Avoid attach and use with which is a temporary attach that won't be 
subject to that problem.

On 2/2/2010 11:51 AM, Marlin Keith Cox wrote:
> Here is a runable program.  When I plot Day and Wgt, it graphs all the data
> points.  All I need is daily.sub1 plotted.  I also need each "Tanks" to have
> its own col or pch.  When I run it with the line with pch, it gives me
> nothing.
> rm(list=ls())
> Trial<-rep(c(1,2),each=12)
> Tanks=rep(c("a3","a4","c4","h4"),each=3,2)
> Day=rep(c(1:12),2)
> Wgt=c(1:24)
> daily<-cbind(Trial, Tanks, Day, Wgt)
> daily
> daily.sub<-subset(daily, subset=Trial==2&  Tanks=="a4"|Trial==2&
> Tanks=="c4"|Trial==2&  Tanks=="h4")
> daily.sub1<-as.data.frame(daily.sub)
> attach(daily.sub1)
> daily.sub1
> x11()
> plot(Day, Wgt)
> #plot(Day, Wgt, pch=c(2,19,21)[Tanks])
> detach(daily.sub1)

More information about the R-help mailing list