[Rd] unexpected '[-.data.frame' result

2005-10-26 Thread Charles C. Berry

Is this a bug?

If not, I am curious to know why '[-.data.frame' was designed to yield 
a.frame$y != a.frame$z rather than refusing to carry out the operation at 
all.

 a.frame - data.frame( x=letters[1:5] )
 a.frame[ 2:5, y ] - letters[2:5]
 a.frame[[ z ]][ 2:5 ] - letters[2:5]
 a.frame
   xyz
1 ab NA
2 bcb
3 cdc
4 ded
5 e NAe

Chuck


Charles C. Berry(858) 534-2098
  Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]   UC San Diego
http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] unexpected '[-.data.frame' result

2005-10-26 Thread Peter Dalgaard
Charles C. Berry [EMAIL PROTECTED] writes:

 Is this a bug?
 
 If not, I am curious to know why '[-.data.frame' was designed to yield 
 a.frame$y != a.frame$z rather than refusing to carry out the operation at 
 all.
 
  a.frame - data.frame( x=letters[1:5] )
  a.frame[ 2:5, y ] - letters[2:5]
  a.frame[[ z ]][ 2:5 ] - letters[2:5]
  a.frame
xyz
 1 ab NA
 2 bcb
 3 cdc
 4 ded
 5 e NAe

It sure looks like a bug, and we're not even prototype-compatible:

turmalin:~/Splus
S-PLUS : Copyright (c) 1988, 2003 Insightful Corp.
S : Copyright Lucent Technologies, Inc.
Version 6.2.1  for Linux 2.4.18 : 2003
Working data will be in /home/bs/pd/MySwork
 a.frame - data.frame( x=letters[1:5] )
  a.frame[ 2:5, y ] - letters[2:5]
 a.frame
  x y
1 a
2 b b
3 c c
4 d d
5 e e

(S-PLUS doesn't know about character NA, so it's not surprising that
you get an empty cell, but it does fill in the right rows of y).

Why would you expect the operation to be refused?

The problem is not, BTW, restricted to character column indexing:

 a.frame
  x y   V3
1 a bb
2 b bc
3 c cd
4 d de
5 e e NA

The problem would seem to be the else clause in

if (jj = nvars) {
if (length(dim(x[jj])) != 2)
  x[[jj]][iseq] - vjj
else x[[jj]][iseq, ] - vjj
}
else {
length(vjj) - nrows
x[[jj]] - vjj
}

which I think wants to be

else {
x[[jj]] - vjj[FALSE]
length(x[[jj]]) - nrows
x[[jj]][iseq] - vjj
}



-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] unexpected '[-.data.frame' result

2005-10-26 Thread Charles C. Berry
On Wed, 26 Oct 2005, Peter Dalgaard wrote:

 Charles C. Berry [EMAIL PROTECTED] writes:

 Is this a bug?

 If not, I am curious to know why '[-.data.frame' was designed to yield
 a.frame$y != a.frame$z rather than refusing to carry out the operation at
 all.

 a.frame - data.frame( x=letters[1:5] )
 a.frame[ 2:5, y ] - letters[2:5]
 a.frame[[ z ]][ 2:5 ] - letters[2:5]
 a.frame
xyz
 1 ab NA
 2 bcb
 3 cdc
 4 ded
 5 e NAe

 It sure looks like a bug, and we're not even prototype-compatible:


[stuff deleted]


 Why would you expect the operation to be refused?


I was having trouble deciding if the use of whole in the 
Extract.data.frame help page was a warning against creating columns with 
only some entries present:

The replacement methods can be used to add whole column(s)...

[rest deleted]

Charles C. Berry(858) 534-2098
  Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]   UC San Diego
http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel