[R] Pure curiosity
Michael Bedward
michael.bedward at gmail.com
Mon Dec 13 04:48:08 CET 2010
Just to follow up on Robert's comment,
If you do an ls() you'll see that you've created objects V1, V2 in
your global environment.
A very similar question was discussed last week (I think... it's all a
blur) in the context of using "<-" instead of "=" with named function
arguments.
Michael
On 13 December 2010 14:10, robert denham <rjadenham at gmail.com> wrote:
> On Mon, Dec 13, 2010 at 1:09 PM, robert denham <rjadenham at gmail.com> wrote:
>
>> in
>> test <- data.frame(V1=c(1,2,3), V2=c(4,5,6))
>>
>> you are using arguments to the data.frame function in the tag=value format.
>> From the help:
>>
>> ...: these arguments are of either the form ‘value’ or ‘tag =
>> value’. Component names are created based on the tag (if
>> present) or the deparsed argument itself.
>>
>> in
>> test <- data.frame(V1<-c(1,2,3), V2<-c(4,5,6))
>> you are using the value part, with the values being c(1,2,3) and c(4,5,6).
>> Someone might explain whats really going on, but I don't think the
>> assignment
>> of c(1,2,3) to the variable V1 is done before the data.frame is evaluated.
>>
>>
>>
>>
>>
>> On Mon, Dec 13, 2010 at 12:53 PM, Matt Cooper <mattcstats at gmail.com>wrote:
>>
>>> Pure curiosity but does anyone know why '<-' and '=' generate different
>>> columning headers?
>>>
>>> > test <- data.frame(V1=c(1,2,3), V2=c(4,5,6))
>>> > test
>>> V1 V2
>>> 1 1 4
>>> 2 2 5
>>> 3 3 6
>>>
>>> > test <- data.frame(V1<-c(1,2,3), V2<-c(4,5,6))
>>> > test
>>> V1....c.1..2..3. V2....c.4..5..6.
>>> 1 1 4
>>> 2 2 5
>>> 3 3 6
>>>
>>> > names(test)
>>> [1] "V1....c.1..2..3." "V2....c.4..5..6."
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list