r - How to remove header part of output from sapply -
i have data.frame , want mean of every column. applied sapply , got following
hour minute totalday totalhour 0.00 17.33 105.93 2542.41 i want remove header part of output sapply looks like:
0.00 17.33 105.93 2542.41 any on how can highly appreciated.
thanks
(code pasting comment wasn't working i'd've liked). again, isn't colmeans() designed do? easier reproduce if more code/data in original q.
dat <- data.frame(x = sample(1000,10), y = sample(1000,10), z = sample(1000,10)) print(dat) ## x y z ## 1 565 374 88 ## 2 347 688 896 ## 3 478 542 508 ## 4 103 350 122 ## 5 115 61 175 ## 6 573 164 543 ## 7 371 304 486 ## 8 437 659 140 ## 9 532 510 61 ## 10 47 227 738 print(as.numeric(colmeans(dat))) ## [1] 356.8 387.9 375.7 as ananda mahto pointed out in comments (but assumed obvious after unfamiliar colmeans() did ?colmeans in r console (we don't cut/paste code stack*, right? :-) colmeans() isn't stripping labels, as.numeric() is. pointed out colmeans() suggest avoiding *apply() calls column means there built-in alternatives. yes, there times when doing *apply() column means make sense, not in case (imo).
Comments
Post a Comment