[R] apply and sapply oddity

Brian zenlines at gmail.com
Wed Oct 24 00:56:43 CEST 2012


Hi List,

why are the results of the two bits of below code different?

 > sapply(1:ncol(d.f), function(i) mode(d.f[,i]))
  [1] "character" "character" "numeric"   "numeric"   "numeric" "numeric"
  [7] "numeric"   "numeric"   "numeric"   "numeric"   "numeric" "numeric"
[13] "numeric"   "numeric"   "character"
 > apply(d.f, 2, mode)
          stn         time     gre000z0     prestas0     tre200s0 ure200s0
  "character"  "character"  "character"  "character"  "character" 
"character"
     usp200s0     fve010z0     dkl010z0        chron      CO_sync 
CO2_dry_sync
  "character"  "character"  "character"  "character"  "character" 
"character"
CH4_dry_sync     H2O_sync       wd.bin
  "character"  "character"  "character"

I am a bit vexed. I thought those two would be equivalent.

Cheers,
Brian



More information about the R-help mailing list