[R] apply function

From: Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
Date: Thu, 15 May 2008 12:18:58 +0530


Hi R,  

Getting a strange result using ?apply. Please look into the below codes:  

>
d=data.frame(a=c(1,2,3),b=c("A","B","C"),c=c(TRUE,FALSE,FALSE),d=c(T,F,F ))

> class(d[,1])

[1] "numeric"

> class(d[,2])

[1] "factor"

> class(d[,3])

[1] "logical"

> class(d[,4])

[1] "logical"    

> apply(d,2,class)

          a b c d

"character" "character" "character" "character"

> apply(d[,c(1,3)],2,class)

        a c

"numeric" "numeric"

> apply(d[,c(3,4)],2,class)

        c d

"logical" "logical"

> apply(d[,c(3,2)],2,class)

          c b

"character" "character"

>
   

Why is this so? How do I get the actual classes of columns of my dataframe d?  

Thanks,

Shubha  

This e-mail may contain confidential and/or privileged i...{{dropped:13}}



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. Received on Thu 15 May 2008 - 06:59:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 15 May 2008 - 11:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive