Contents

1 str_replace
2 format
3 01,02,03.. 형태로 만들기
4 vector to string
5 날짜 관련
6 string split


1 str_replace #

library(stringr)
colnames(gender) <- str_replace(colnames(gender), "\.", " ")

2 format #

format.png
> as.character(format(Sys.Date(), format="%Y%m%d"))
[1] "20150408"

3 01,02,03.. 형태로 만들기 #

library("stringr")
> str_sub(paste0("00", 1:10), -2, -1)
 [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10"

4 vector to string #

a <- c("aa", "bb", "cc")
paste(a,collapse="")

5 날짜 관련 #

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")

6 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, ","))