String <- c("Happy","Birthday","to","You")
length(String)
## [1] 4
sum(nchar(String))
## [1] 18
“Happy Birthday to You”
String2 <- paste(String,collapse = " ")
String2
## [1] "Happy Birthday to You"
length(String2)
## [1] 1
nchar(String2)
## [1] 21
“A 1” “B 2” “C 3” “D 4” “E 5” “F 6” “G 7” “H 8” “I 9” “J 10”
“A1” “B2” “C3” “D4” “E5” “F6” “G7” “H8” “I9” “J10”
paste(LETTERS[1:10],1:10,sep=" ")
## [1] "A 1" "B 2" "C 3" "D 4" "E 5" "F 6" "G 7" "H 8" "I 9" "J 10"
paste(LETTERS[1:10],1:10,sep="")
## [1] "A1" "B2" "C3" "D4" "E5" "F6" "G7" "H8" "I9" "J10"
paste ( c(“red”, “blue” ) , “pen” ) paste ( c(“red”, “blue” ) , “pen” , sep=”-” ) paste ( c(“red”, “blue” ) , “pen” , collapse=”; ”) paste ( c(“red”, “blue” ) , “pen” , sep=”-”, collapse=”; ” )
paste(c("red","blue"),"pen")
## [1] "red pen" "blue pen"
paste(c("red","blue"),"pen",sep = "-")
## [1] "red-pen" "blue-pen"
paste(c("red","blue"),"pen",collapse = "; ")
## [1] "red pen; blue pen"
paste(c("red","blue"),"pen",sep = "-",collapse = "; ")
## [1] "red-pen; blue-pen"
[[1]]
[1] “Good”
[[2]]
[1] “Morning”
str1 <- strsplit("Good Morning"," ")[[1]][1]
str2 <- unlist(strsplit("Good Morning"," "))[2]
list(str1, str2)
## [[1]]
## [1] "Good"
##
## [[2]]
## [1] "Morning"
c(“Yesterday is history, tomorrow is a mystery, today is a gift !”,”That’s why we call it the present - from kung Fu Panda”)
Text <- c("Yesterday is history, tomorrow is a mystery, today is a gift !","That’s why we call it the present - from kung Fu Panda")
Text <- gsub(",","",Text)
Text <- sub("- ","",Text)
strsplit(Text, split = " ")
## [[1]]
## [1] "Yesterday" "is" "history" "tomorrow" "is" "a"
## [7] "mystery" "today" "is" "a" "gift" "!"
##
## [[2]]
## [1] "That’s" "why" "we" "call" "it" "the" "present"
## [8] "from" "kung" "Fu" "Panda"
outer(1:6,1:6,FUN = paste,sep=" ")
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] "1 1" "1 2" "1 3" "1 4" "1 5" "1 6"
## [2,] "2 1" "2 2" "2 3" "2 4" "2 5" "2 6"
## [3,] "3 1" "3 2" "3 3" "3 4" "3 5" "3 6"
## [4,] "4 1" "4 2" "4 3" "4 4" "4 5" "4 6"
## [5,] "5 1" "5 2" "5 3" "5 4" "5 5" "5 6"
## [6,] "6 1" "6 2" "6 3" "6 4" "6 5" "6 6"
“941215-1234567” ”850605-2345678” ”760830-1357913”
ssn <- c("941215-1234567","850605-2345678","760830-1357913")
ssn
## [1] "941215-1234567" "850605-2345678" "760830-1357913"
ssn <- gsub("[0-9]{7}$","*******",ssn) # paste(substr(ssn, 1, 7), "*******", sep="")
ssn
## [1] "941215-*******" "850605-*******" "760830-*******"
index <- grep(pattern = "New",rownames(USArrests))
USArrests[index,]
## Murder Assault UrbanPop Rape
## New Hampshire 2.1 57 56 9.5
## New Jersey 7.4 159 89 18.8
## New Mexico 11.4 285 70 32.1
## New York 11.1 254 86 26.1
colMeans(USArrests[index,])
## Murder Assault UrbanPop Rape
## 8.000 188.750 75.250 21.625
txt <- c(“a” ,”ab” ,”acb” ,”accb” ,”accccb” ,”acccccb”)
grep(“ac?b” , txt , value=TRUE)
grep(“ac*b” , txt , value=TRUE)
grep(“ac+b” , txt , value=TRUE)
txt <- c("a","ab","acb","accb","accccb","acccccb")
grep("ac?b",txt,value = TRUE)
## [1] "ab" "acb"
grep("ac*b",txt,value = TRUE)
## [1] "ab" "acb" "accb" "accccb" "acccccb"
grep("ac+b",txt,value = TRUE)
## [1] "acb" "accb" "accccb" "acccccb"
# data <- data.frame(Datetime=c("12/25/2020 23:59:59","1/25/2021 23:59:59","2/25/2021 23:59:59"))
Datetime <- c("12/25/2020 23:59:59","1/25/2021 23:59:59","2/25/2021 23:59:59")
data <- as.data.frame(Datetime)
data
## Datetime
## 1 12/25/2020 23:59:59
## 2 1/25/2021 23:59:59
## 3 2/25/2021 23:59:59
data$Datetime <- strptime(data$Datetime, format="%m/%d/%Y %H:%M:%S")
data
## Datetime
## 1 2020-12-25 23:59:59
## 2 2021-01-25 23:59:59
## 3 2021-02-25 23:59:59
str(data)
## 'data.frame': 3 obs. of 1 variable:
## $ Datetime: POSIXlt, format: "2020-12-25 23:59:59" "2021-01-25 23:59:59" ...
“월-0601” “화-0602” “수-0603” “목-0604” “금-0605” “토-0606” “일-0607”
start <- as.Date("2020-06-01")
x <- seq(from=start, by=1, length.out = 7)
format(x,format= "%a-%m%d")
## [1] "월-0601" "화-0602" "수-0603" "목-0604" "금-0605" "토-0606" "일-0607"
“December 25, 2020” “January 25, 2021” “February 25, 2022”
x <- as.Date(c("2020년 12월 25일","2021년 1월 25일","2022년 2월 25일"),format="%Y년 %B %d일")
Sys.setlocale("LC_ALL", "English")
## [1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
format(x,"%B %d, %Y")
## [1] "December 25, 2020" "January 25, 2021" "February 25, 2022"