Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?
On 2010-08-05 12:14, Ulrike Grömping wrote: Gabor Grothendieck schrieb: On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping groemp...@bht-berlin.de wrote: Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as documented), but when assigning a value, a new column with the partial name is added to the data frame that is identical to the original column except for the changed value. Is that intentional ? An example: Note that the lack of partial matching when performing assignment is also documented. See second last paragraph in Details section of ?Extract Yes, I see, thanks. I looked at ?[.data.frame, where this is not documented. However, given the documentation that partial matching is not used on the left-hand side, I would have expected even more that the assignment sw$Fert[1]- 10 works differently, because I am using it on the left-hand side. Probably, extraction ([1]) is done first here, so that the right-hand side won. At least, this is very confusing. Best, Ulrike This is another example of why it's a good idea to avoid the '$' notation when fiddling with data frames. Try this: sw - swiss[1:5, 1:4] sw[[Fert]] sw[[Fert]] - 10 and my preferred version: sw[, Fert] sw[, Fert] - 10 I've never liked partial matching for data frames. -Peter Ehlers __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?
On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping groemp...@bht-berlin.de wrote: Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as documented), but when assigning a value, a new column with the partial name is added to the data frame that is identical to the original column except for the changed value. Is that intentional ? An example: Note that the lack of partial matching when performing assignment is also documented. See second last paragraph in Details section of ?Extract __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?
Gabor Grothendieck schrieb: On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping groemp...@bht-berlin.de wrote: Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as documented), but when assigning a value, a new column with the partial name is added to the data frame that is identical to the original column except for the changed value. Is that intentional ? An example: Note that the lack of partial matching when performing assignment is also documented. See second last paragraph in Details section of ?Extract Yes, I see, thanks. I looked at ?[.data.frame, where this is not documented. However, given the documentation that partial matching is not used on the left-hand side, I would have expected even more that the assignment sw$Fert[1] - 10 works differently, because I am using it on the left-hand side. Probably, extraction ([1]) is done first here, so that the right-hand side won. At least, this is very confusing. Best, Ulrike __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?
Ulrike Grömping wrote: However, given the documentation that partial matching is not used on the left-hand side, I would have expected even more that the assignment sw$Fert[1] - 10 works differently, because I am using it on the left-hand side. Probably, extraction ([1]) is done first here, so that the right-hand side won. At least, this is very confusing. I totally agree! I think that sw - data.frame(Fertility=1:5) sw$Fert[1] - 10 should work either like sw$Fert2[1] - 10 i.e. create new column, containing just 10. or like sw$Fertility[1] - 10 i.e. replace the 1st item in sw$Fertility by 10. -- View this message in context: http://r.789695.n4.nabble.com/Assignment-of-individual-values-to-data-frame-columns-intentional-or-unintentional-behavior-tp2315105p2315641.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel