[R] numbers not behaving as expected

Steve_Friedman at nps.gov Steve_Friedman at nps.gov
Thu Apr 9 19:39:06 CEST 2009


If someone can explain this odd behavior I'd appreciate it.

I have a data.frame Cell.ave (attached and created via dput(Cell.ave,
"Cell.ave")
which contains three columns of parameters year, month and AveRain.

I need to subset the data.frame by months such that

DrySeaonMonths are 1,2,3,4, 11, and 12 or Jan - April, November and
December

and

WetSeasonMonths are 5:10 or May-October.

I'm using the following code:

> DrySeasonMonths <- Cell.ave[Cell.ave$month < "5" & Cell.ave$month !=
"10",]
> table(DrySeasonMonth$month)
    1    2   3    4     11   12
 36   36  36  36  36   36

#  this is expected since the data is for 36 years

WetSeasonMonths <- Cell.ave[Cell.ave$month  >= "5" & Cell.ave$month <=
"11",]
 WetSeasonMonths
[1] year    month   AveRain
<0 rows> (or 0-length row.names)
>

There is an obvious problem with how the values for month are being stored.
I've tried converting them to factors, which complines that the subsetting
routine is not appropriate for factors. And I've tried as.numeric which
also does not return an working dataframe.

all suggestions to solve this are appreciated.

Thanks Steve

(See attached file: Cell.ave)

sessionInfo()
R version 2.8.1 (2008-12-22)
x86_64-redhat-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

Steve_Friedman at nps.gov
Office (305) 224 - 4282
Fax     (305) 224 - 4147


More information about the R-help mailing list