[R] subset

Felipe Carrillo mazatlanmexico at yahoo.com
Mon Nov 29 22:02:22 CET 2010


 Hi:
I always use subset the same way but now is returning 0 rows. 
What's wrong with the way I am subsetting?

library(ggplot2)
structure(list(first = c(38.2086, 43.1768, 43.146, 41.8044, 42.4232, 
46.3646, 38.0813, 40.0745, 40.4889, 38.6246, 40.2826, 41.6056, 
34.5353, 40.0768), second = c(43.3295, 42.4326, 38.8994, 37.0894, 
42.3218, 46.1726, 39.1206, 41.2072, 42.4874, 40.2657, 38.7766, 
40.8822, 42.0165, 49.2055), third = c(42.24, 42.992, 37.7419, 
42.3448, 41.9131, 44.385, 42.7811, 44.1963, 40.8088, 43.9634, 
38.7079, 38.0791, 44.3136, 39.5333)), .Names = c("first", "second", 
"third"), class = "data.frame", row.names = c(NA, -14L))
 head(x);str(x)
xmelt <- melt(x)
 names(xmelt) <- c("year","fatPerc")
  str(xmelt);xmelt
 # Subset to plot only the 'first' and third year
firstyear <- subset(xmelt,year ==' first');str(firstyear) # works
# two variables,,doesn't work
firstyear <- subset(xmelt,year ==' first' & year == 'third');str(firstyear)
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA






More information about the R-help mailing list