Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "df[] <-" do in R

Pretty simple question, and I have had a quick search in google and stackoverflow. I found this in another post: In aggregate: sum not meaningful for factors.

df[] <- lapply(df, function(x) type.convert(as.character(x)))

how does df[] work?

like image 978
CArnold Avatar asked Jan 16 '14 15:01

CArnold


1 Answers

To add to what Roland wrote,{edit} aaagh he ninja'd me w/ his comment the point is that using DF[] retains the existing object DF with its attributes, in this case the fact that it's got two dimensions and the names a and b .

Rgames> foo<- matrix(1:6,2,3)
Rgames> foo[]<-7:12
Rgames> foo
     [,1] [,2] [,3]
[1,]    7    9   11
[2,]    8   10   12
Rgames> foo<-7:12
Rgames> foo
[1]  7  8  9 10 11 12
like image 199
Carl Witthoft Avatar answered Oct 13 '22 01:10

Carl Witthoft