#title String 처리 [[TableOfContents]] ==== str_replace ==== {{{ library(stringr) colnames(gender) <- str_replace(colnames(gender), "\.", " ") }}} ==== format ==== * http://www.dummies.com/how-to/content/how-to-format-numbers-in-r.html * http://www.stat.berkeley.edu/~s133/dates.html * http://www.statmethods.net/input/dates.html * http://www.r-bloggers.com/date-formats-in-r/ attachment:RTips/format.png {{{ > as.character(format(Sys.Date(), format="%Y%m%d")) [1] "20150408" }}} ==== 01,02,03.. 형태로 만들기 ==== {{{ library("stringr") > str_sub(paste0("00", 1:10), -2, -1) [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" }}} ==== vector to string ==== {{{ a <- c("aa", "bb", "cc") paste(a,collapse="") }}} ==== 날짜 관련 ==== date to character {{{ strftime(as.Date("2013-12-01")) }}} {{{ yyyymmdd <- xpathSApply(doc,"//div[@class='filter-item' and @control-filter='daily']//a[@class='current']", xmlValue) generate_time <- xpathSApply(doc,"//div[@class='generate-time' and @data-meta='generate-time']//b", xmlValue) Sys.setlocale("LC_TIME","English") #"Jul 23, 2014 10:00am UTC+9" crawling_time <- strptime(paste(yyyymmdd, generate_time), "%b %d, %Y %I:%M%p", tz="") std_dt <- substr(crawling_time,1,10) Sys.setlocale("LC_TIME","Korean_Korea.949") }}} ==== string split ==== {{{ s <- c("a", "b", "c") v <- unique(tolower(strsplit(s, ","))) paste(v, collapse=',') }}} {{{ (csv <- paste(as.character(1:5), collapse=", ")) unlist(strsplit(csv, ",")) }}}