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

From: Marc Schwartz (via MN) <>
Date: Wed 16 Aug 2006 - 03:19:35 EST

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)

[1] "numeric"

[1] "numeric"

[1] "numeric"

[1] "numeric"

[1] "factor"


> sapply(iris, class)

Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species
   "numeric"    "numeric"    "numeric"    "numeric"     "factor"

See ?lapply and ?sapply

HTH, Marc Schwartz mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Aug 16 03:26:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 16 Aug 2006 - 06:21:33 EST.

Mailing list information is available at Please read the posting guide before posting to the list.