Code:
fruits <- "apples, oranges, pears"
nchar(fruits)
[1] 22
substring(fruits, 1, 6)
[1] "apples"
fruits<- substring(fruits, c(1, 9, 18), c(6, 15, 22))
fruits
[1] "apples" "oranges" "pears"
paste(5, "apples")
[1] "5 apples"
nfruits <- c(5, 9, 2)
paste(nfruits, fruits)
[1] "5 apples" "9 oranges" "2 pears"
paste(fruits, nfruits, sep = " = ")
[1] "apples = 5" "oranges = 9" "pears = 2"
colourStrings <- c("green", "blue", "orange", "red", "yellow", + "lightblue", "navyblue", "indianred")
grep("red", colourStrings, value = TRUE)
[1] "red" "indianred"
colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("^red", colourStrings, value = TRUE)
[1] "red"
grep("red$", colourStrings, value = TRUE)
[1] "red" "indianred"
grep("r+", colourStrings, value = TRUE)
[1] "green" "orange" "red" "indianred"
grep("e[2]", colourStrings, value = TRUE)
character(0)
grep("e{2}", colourStrings, value = TRUE)
[1] "green"
gsub("red". "brown", colourStrings)
[1] "green" "blue" "orange" "brown" "yellow" "lightblue" "navyblue" "indianbrown"
eto po yong error
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.