[R] 1.8.1 and subsetting dataframes
Patrick Connolly
p.connolly at hortresearch.co.nz
Mon Nov 24 22:23:46 CET 2003
I've encountered something that didn't arise using earlier versions of
R (Linux).
A dataframe is created and new columns added to it by doing
calculations using apply with various functions on some of the
original columns. It's somewhat too involved to give a toy example
that's reproducible. However, the resulting phenemonon can be
characterised by the following:
Browse[1]> dim(mod.df)
[1] 409 5
Browse[1]> object.size(mod.df)
[1] 31520
Browse[1]> is.array(mod.df)
[1] FALSE
Browse[1]> mod.df[1:5,]
Error in as.data.frame.default(x[[i]], optional = TRUE) :
can't coerce array into a data.frame
The whole dataframe would display correctly, so I figured it couldn't
have much wrong with it. So I tried this:
Browse[1]> write.table(mod.df, "mod.tmp", quote = F, sep = "\t", row.names = F)
Browse[1]> mod.df <- read.table("mod.tmp", T, sep = "\t")
Browse[1]> is.array(mod.df)
[1] FALSE
Browse[1]> object.size(mod.df)
[1] 16164
Browse[1]> mod.df[1:5,]
Site System Cultivar Type CFU
1 Canterbury ifp braeburn fruit 388
2 Canterbury ifp braeburn fruit 920
3 Canterbury ifp braeburn fruit 868
4 Canterbury ifp braeburn fruit 328
5 Canterbury ifp braeburn fruit 656
The size of the object using R-1.8.0 (which had no subsetting
problems) was
Browse[1]> object.size(mod.df)
[1] 21160
I suspect it could have something to do with some of the changes
mentioned in this part of the NEWS file:
o Subscripting for data.frames has been rationalized:
But I'm not smart enough to see what in those dozen or so would have a
bearing on this case. I don't think the drop argument comes into what
I've done.
If that's not sufficient to give anyone a hint what could be
happening, I'll have another attempt to get a toy version.
Thanks.
PS: Is there a more elegant way using a text connection instead or
creating a temporary file in my work around?
--
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
More information about the R-help
mailing list