[R] How to show classes of all columns of a data frame?

2006-08-15 Thread T Mu
Hi all,

Suppose I have a data frame myDF, col A is factor, col B is numeric, col C
is character. I can get their classes by

 class(myDF$A)

but is there a quick way to show what classes of all columns are? Thank you.

Tian

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] How to show classes of all columns of a data frame?

2006-08-15 Thread Marc Schwartz (via MN)
On Tue, 2006-08-15 at 13:10 -0400, T Mu wrote:
 Hi all,
 
 Suppose I have a data frame myDF, col A is factor, col B is numeric, col C
 is character. I can get their classes by
 
  class(myDF$A)
 
 but is there a quick way to show what classes of all columns are? Thank you.
 
 Tian

Depending upon the output format you desire:

 lapply(iris, class)
$Sepal.Length
[1] numeric

$Sepal.Width
[1] numeric

$Petal.Length
[1] numeric

$Petal.Width
[1] numeric

$Species
[1] factor


or

 sapply(iris, class)
Sepal.Length  Sepal.Width Petal.Length  Petal.Width  Species
   numericnumericnumericnumeric factor


See ?lapply and ?sapply


HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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.