[R] dataframe columns class

Cleber N.Borges klebyn at yahoo.com.br
Sun Dec 18 18:07:52 CET 2016


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



More information about the R-help mailing list