I'm not sure if the following is a bug or a feature:
> jjmat <- array(1:6, c(2,3), list(c('ABC', 'DEF'),
c('xyz', 'tuv',
'qrs')))
> jjdf <- as.data.frame(jjmat)
> jjmat['AB', ]
Error: subscript out of bounds
> jjdf['AB',]
xyz tuv qrs
ABC 1 3 5
> jjmat[, 'tu']
Error: subscript out of bounds
> jjdf[, 'tu']
Error in "[.data.frame"(jjdf, , "tu") : undefined columns
selected
The questionable behaviour is that partial matching of dimnames
is not allowed except for the rows in data frames.
(This is 1.8.0 alpha -- 1.7 would have given NULL when the
column of a data frame was partially matched.)
Without good arguments to the contrary, I would lean toward
partial matching not being allowed at all. (And so would my
client who got confused about this -- which is the reason I started
looking at it.)
Also there is a typo in the [.data.frame help file, in the Warning
section:
To drop from a data frame to a list, 'drop = FALSE' has
to specified explicitly.
should read:
To drop from a data frame to a list, 'drop = TRUE' has
to be specified explicitly.
Patrick Burns
Burns Statistics
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Patrick Burns <pburns@pburns.seanet.com> writes:> I'm not sure if the following is a bug or a feature: > > > jjmat <- array(1:6, c(2,3), list(c('ABC', 'DEF'), c('xyz', 'tuv', > 'qrs'))) > > jjdf <- as.data.frame(jjmat) > > jjmat['AB', ] > Error: subscript out of bounds > > jjdf['AB',] > xyz tuv qrs > ABC 1 3 5 > > jjmat[, 'tu'] > Error: subscript out of bounds > > jjdf[, 'tu'] > Error in "[.data.frame"(jjdf, , "tu") : undefined columns selected > > The questionable behaviour is that partial matching of dimnames > is not allowed except for the rows in data frames. > > (This is 1.8.0 alpha -- 1.7 would have given NULL when the > column of a data frame was partially matched.) > > Without good arguments to the contrary, I would lean toward > partial matching not being allowed at all. (And so would my > client who got confused about this -- which is the reason I started > looking at it.)Hmm, I'm inclined to agree, but the pmatch in "[.data.frame" does seem pretty deliberate. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907