[R] subsetting data set dimenion problem
Clint Harshaw
charshaw at presby.edu
Sun Feb 27 15:08:36 CET 2005
(See DAAG book, p. 173, ex. 3)
I'm a new user of R, and I'm following the DAAG text. I want to create a
subset of the races2000 data frame, but get errors because of a mismatch
of values in some columns:
> library(DAAG)
> attach(races2000)
> hills2000 <- races2000[races2000$type == 'hill']
Error in as.matrix.data.frame(x) : dim<- : dims [product 770] do not
match the length of object [771]
However, if I follow the solution given, and remove redundant columns 1
through 6 and column 11 (which I won't need, since I know they are going
to have the same value), I don't get the error:
> hills2000 <- races2000[races2000$type == 'hill', -c(1:6,11)]
> hills2000
dist climb time timef
Tiso Carnethy 6.00 2500 0.7822222 0.9191667
[...]
Cornalees 5.50 800 0.6183333 NA
[...]
What is causing the error with my original subsetting? I speculated it
was related to the NA values, but there is an NA in the resulting
hills2000, corresponding to the Cornalees hill race.
Thanks,
Clint
--
Clint Harshaw, PhD
Department of Mathematics
Presbyterian College
Clinton SC 29325
EMail: charshaw at presby.edu
Phone: 864.833.8995
Fax: 864.938.3769
Office: Harrington-Peachtree Rm 412
More information about the R-help
mailing list