[R] Strange names when creating a data.frame: Difference between <- and =

Vladimir Eremeev wl2776 at gmail.com
Tue Oct 2 21:29:23 CEST 2007




John Kane-2 wrote:
> 
> This is just a curiosity question.  Why do the two
> different syntaxes for df1 and df2 give such different
> results in the names(dfx)?
> 
> Thanks
> 
> 
> df1 <- data.frame(nas = c("A",  "B" , "B" ,"C" ,"B",
> "A", "D"),nums = c(3,    2,    1,   1,   2,    3,  7))
> 
> df2 <- data.frame(nas  <- c("A",  "B" , "B" ,"C" ,"B",
> "A", "D"),nums  <- c(3,    2,    1,   1,   2,    3, 
> 7))
> 
> df1; df2
> 
>>df1
>   nas nums
> 1   A    3
> 2   B    2
>     .   .
> 
>>  df2
> 
>    nas....c..A....B....B....C....B....A....D..
> nums....c.3..2..1..1..2..3..7.
> 1                                           A         
>                     3
> 2                                           B         
>                     
> 3
> .                                           .
> 
You specify argument names in the first function call in the form
agrument.name=value
Argument names become column names in the data frame.
"<-" is the assignment operator, it returns the assigned value,  it is not
the specification of a function argument. 

Second function call does not contain argument names, so, they are
constructed from expressions.
You should have the variables nas and nums in your workspace now.
ls() should show them.
If you type data.frame (without parentheses, "(" and ")") on the R command
prompt it will print the body of this function. You can study it and
discover how it works.
-- 
View this message in context: http://www.nabble.com/Strange-names-when-creating-a-data.frame%3A-Difference-between-%3C--and-%3D-tf4557141.html#a13006205
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list