[R] apply problem

aedin culhane aedin at jimmy.harvard.edu
Fri Apr 13 19:45:06 CEST 2007


Dear R-Help
I am running apply on a data.frame containing factors and numeric 
columns.  It appears to convert are columns into as.character? Does it 
convert data.frame into matrix? Is this expected? I wish it to recognise 
numerical columns and round numbers.  Can I use another function instead 
of apply, or should I use a for loop in the case?

 > summary(xmat)
        A               B             C             D
  Min.   :  1.0   414    :  1   Stage 2:  5   Min.   :-0.075369
  1st Qu.:113.8   422    :  1   Stage 3:  6   1st Qu.:-0.018102
  Median :226.5   426    :  1   Stage 4:441   Median :-0.003033
  Mean   :226.5   436    :  1                 Mean   : 0.008007
  3rd Qu.:339.2   460    :  1                 3rd Qu.: 0.015499
  Max.   :452.0   462    :  1                 Max.   : 0.400578
                  (Other):446
        E                F                G
  Min.   :0.2345   Min.   :0.9808   Min.   :0.01558
  1st Qu.:0.2840   1st Qu.:0.9899   1st Qu.:0.02352
  Median :0.3265   Median :0.9965   Median :0.02966
  Mean   :0.3690   Mean   :1.0079   Mean   :0.03580
  3rd Qu.:0.3859   3rd Qu.:1.0129   3rd Qu.:0.03980
  Max.   :2.0422   Max.   :1.3742   Max.   :0.20062

 > for(i in 1:7) print(class(xmat[,i]))
[1] "integer"
[1] "factor"
[1] "factor"
[1] "numeric"
[1] "numeric"
[1] "numeric"
[1] "numeric"

 > apply(xmat, 2, class)
           A           B           C           D           E           F
"character" "character" "character" "character" "character" "character"
           G
"character"



Thanks for your help
Aedin



More information about the R-help mailing list