[R] created data doesn't remain when split...

Jeff D. Hamann jeff.hamann at forestinformatics.com
Thu Nov 6 18:16:52 CET 2003


I've been trying to figure out why the following is happening....

I've got some data I'll load in from a file...

rm(list=ls(all=TRUE))
trees <- read.table( "c:/cruisepak/data.txt", header=T)
trees$ct <- 1

And when I create some temp variable, then split the data to perform further
processing, the additional column doesn't maintain the data correctly....

mtrees <- trees[trees$m == 1,]
ctrees <- trees[trees$m == 0,]

The results are as follows...

> trees
plot tree m sp dbh tht ct
1      1    1 1 DF  44 185 1
3      1    3 0 DF  40 192  1
.....blah, blah, blah......
6      1    6 0 DF  26 156   1
8      1    8 0 DF  26 155   1


but,
>mtrees
    plot tree m sp dbh tht ct
1      1    1 1 DF  44 185     1
2      1    2 1 DF  38 188    NA
17     2    6 1 DF  26 174    NA
26     3    1 1 DF  42 185    NA

and

>ctrees
> ctrees
    plot tree m sp dbh tht  ct
3      1    3 0 DF  40 192    NA
4      1    4 0 DF  33 148    NA
5      1    5 0 DF  43 182    NA

when the value of ct for all the records in all the data.frames should be 1,
not NA.

Why is that? Am I missing a step here? I'm running R 1.7.1 on Win2k.


Jeff.

---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
(office) 541-754-1428
(cell) 541-740-5988
jeff.hamann at forestinformatics.com
www.forestinformatics.com


---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
(office) 541-754-1428
(cell) 541-740-5988
jeff.hamann at forestinformatics.com
www.forestinformatics.com




More information about the R-help mailing list