作者swedrf0112 (M)
看板R_Language
标题Re: [问题] dplyr 与 mutate用法
时间Thu Oct 13 18:51:07 2016
不知道是不是你要的XD
可使用 dplyr::mutate_each_
library(dplyr)
library(magrittr)
d = data.frame(Column1=sample(1:10,10),
Column2=sample(1:10,10),
Column3=sample(1:10,10),
Column18=sample(20:30,10))
transF = function(x){
return( as.POSIXct(as.numeric(x)*(60*60*24), origin="1899-12-30",
tz="UCT") )
}
## 可自己修改成需要的栏位名称 ex: named = c("Column2","Column18")
named = names(d)
d %>% mutate_each_(funs(transF),named)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.231.194.196
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1476355870.A.42B.html
※ 编辑: swedrf0112 (36.231.194.196), 10/13/2016 18:52:53
※ 编辑: swedrf0112 (36.231.194.196), 10/13/2016 18:54:31
1F:→ huangsam: 这个写法我有想到,但是不知道怎麽写,谢谢提供! 10/13 22:34