[R] subset bug?
Berton Gunter
gunter.berton at gene.com
Fri Dec 10 17:57:38 CET 2004
The subset() Help file says
"The select argument exists only for the method for data frames ..."
So if mat is a matrix and not a data.frame, this might be the source of your
problems.
-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
"The business of the statistician is to catalyze the scientific learning
process." - George E. P. Box
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Saunders
> Sent: Friday, December 10, 2004 5:02 AM
> To: R Help
> Subject: [R] subset bug?
>
> I ran into a problem with "subset" while working at home that
> I am not sure is a bug or not. I defined a custom function
> to take a data frame of tree positions, sizes, and types
> (containing the columns TRT, COMP, PLOT, X, Y, DBH and CON)
> and wanted to make a stem map of the plot using different
> symbols and colors to represent the different types of tree
> stems. I copied a bit of the code below, the part that gave
> me troubles:
>
> if(dim(subset(mat,CON==1 & DBH>11.43))[1]>0)
> symbols(mat[mat$CON==1 & mat$DBH>11.43,]$X,mat[mat$CON==1
> & mat$DBH>11.43,]$Y,circles=log(mat[mat$CON==1 &
> mat$DBH>11.43,]$DBH)*tuner,inches=FALSE,add=TRUE,fg="gray",lwd=2)
>
> if(dim(subset(mat,CON==0 & DBH>11.43))[1]>0)
> symbols(mat[mat$CON==0 & mat$DBH>11.43,]$X,mat[mat$CON==0 &
> mat$DBH>11.43,]$Y,squares=log(mat[mat$CON==0 &
> mat$DBH>11.43,]$DBH)*sqrt(pi)*tuner,inches=FALSE,add=TRUE,fg="
> gray",lwd=2)
>
> if(dim(subset(mat,CON==1 & DBH<=11.43))[1]>0)
> symbols(mat[mat$CON==1 & mat$DBH<=11.43,]$X,mat[mat$CON==1 &
> mat$DBH<=11.43,]$Y,circles=log(mat[mat$CON==1 &
> mat$DBH<=11.43,]$DBH)*tuner,inches=FALSE,add=TRUE,fg="black",lwd=2)
>
> if(dim(subset(mat,CON==0 & DBH<=11.43))[1]>0)
> symbols(mat[mat$CON==0 & mat$DBH<=11.43,]$X,mat[mat$CON==0 &
> mat$DBH<=11.43,]$Y,squares=log(mat[mat$CON==0 &
> mat$DBH<=11.43,]$DBH)*sqrt(pi)*tuner,inches=FALSE,add=TRUE,fg=
> "black",lwd=2)
>
> The item "tuner" just scales the symbol size. As you can
> see, I was using two columns to define the type of symbol
> (CON: square vs. circle) and color (DBH: gray vs. black). I
> had to use the "if" statements because some of the plots did
> not contain all combinations of tree types. This worked fine
> in giving me my plots.
>
> Okay, the question I had was why I couldn't use the "subset"
> function within the "symbols" command. I was going to use:
>
> subset(mat,CON==0 & DBH<=11.43,select=c(X,Y))
>
> as the first entry into the symbols command, but it kept
> giving me errors saying "xy.coords" could not convert it.
> However, if I used the "plot" function with "subset" trimming
> the data frame externally, it worked fine to plot the point
> positions. However, the help for "plot" and "plot.default"
> says "xy.coords" is used within that function. What am I
> missing here?
>
> Mike Saunders
> Research Assistant
> University of Maine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list