[R] dataframe columns class

Ista Zahn istazahn at gmail.com
Sun Dec 18 18:22:41 CET 2016


Read ?apply and you shall be be enlightened.

--Ista

On Dec 18, 2016 12:09 PM, "Cleber N.Borges via R-help" <r-help at r-project.org>
wrote:

> Why columns classes are function dependents?
> Like this example:
>
> > for( i in 1:5 ) print( class( iris[,i] ) )
> [1] "numeric"
> [1] "numeric"
> [1] "numeric"
> [1] "numeric"
> [1] "factor"
> >
> > apply( iris, 2, class )
> Sepal.Length  Sepal.Width Petal.Length  Petal.Width Species
>  "character"  "character"  "character"  "character" "character"
> >
>
>
>
> > dat <- data.frame( v1=1:5, v2=letters[1:5] )
> > dat
>   v1 v2
> 1  1  a
> 2  2  b
> 3  3  c
> 4  4  d
> 5  5  e
> >
> > summary( dat )
>        v1    v2
>  Min.   :1   a:1
>  1st Qu.:2   b:1
>  Median :3   c:1
>  Mean   :3   d:1
>  3rd Qu.:4   e:1
>  Max.   :5
> >
> > apply( dat, 2, class )
>          v1          v2
> "character" "character"
> >
>
>
> ---
> Este email foi escaneado pelo Avast antivírus.
> https://www.avast.com/antivirus
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list