Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # data.table做法:
- library(data.table)
- DT[ , lapply(.SD, function(x)iconv(x,"UTF8", "BIG5"))]
- # 如果有numeric或是integer column的話:
- DT[ , lapply(.SD, function(x){
- if (is.character(x))
- iconv(x,"UTF8", "BIG5")
- } else return(x)})]
- # dplyr做法:
- library(dplyr)
- DF %>% mutate_each(funs(iconv(., "UTF8", "BIG5")))
- # 如果有numeric或是integer column的話:
- DF %>% mutate_if(is.character, funs(iconv(., "UTF8", "BIG5")))
- # base函數解法:
- evalExpr <- lapply(names(DF), function(x){
- bquote(iconv(.(as.symbol(x)), "UTF8", "BIG5"))
- })
- do.call(function(...) transform(DF, ...), evalExpr)
- # 如果有numeric或是integer column的話:
- evalExpr <- lapply(names(DF)[sapply(DF, is.character)],
- function(x) bquote(iconv(.(as.symbol(x)), "UTF8", "BIG5")))
- do.call(function(...) transform(DF, ...), evalExpr)
Advertisement
Add Comment
Please, Sign In to add comment