What's new

Patulong naman po ano error sa R program ko newbie po salamat

Lunathicc

Forum Guru
Elite
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
1675425722697.png
 

Attachments

Solution
comment out mo yung mga [1], yun ata yung mga expected output.

tapos yung '+' bago yung "lightblue"

Code:
fruits <- "apples, oranges, pears"
nchar(fruits)

substring(fruits, 1, 6)

fruits<- substring(fruits, c(1, 9, 18), c(6, 15, 22))
fruits

paste(5, "apples")

nfruits <- c(5, 9, 2)

paste(nfruits, fruits)

paste(fruits, nfruits, sep = " = ")

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("red", colourStrings, value = TRUE)

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("^red", colourStrings, value = TRUE)

grep("red$", colourStrings, value = TRUE)

grep("r+", colourStrings, value = TRUE)

grep("e[2]", colourStrings...
comment out mo yung mga [1], yun ata yung mga expected output.

tapos yung '+' bago yung "lightblue"

Code:
fruits <- "apples, oranges, pears"
nchar(fruits)

substring(fruits, 1, 6)

fruits<- substring(fruits, c(1, 9, 18), c(6, 15, 22))
fruits

paste(5, "apples")

nfruits <- c(5, 9, 2)

paste(nfruits, fruits)

paste(fruits, nfruits, sep = " = ")

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("red", colourStrings, value = TRUE)

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("^red", colourStrings, value = TRUE)

grep("red$", colourStrings, value = TRUE)

grep("r+", colourStrings, value = TRUE)

grep("e[2]", colourStrings, value = TRUE)
character(0)
grep("e{2}", colourStrings, value = TRUE)

gsub("red", "brown", colourStrings)
 
Last edited:
Solution
comment out mo yung mga [1], yun ata yung mga expected output.

tapos yung '+' bago yung "lightblue"

Code:
fruits <- "apples, oranges, pears"
nchar(fruits)

substring(fruits, 1, 6)

fruits<- substring(fruits, c(1, 9, 18), c(6, 15, 22))
fruits

paste(5, "apples")

nfruits <- c(5, 9, 2)

paste(nfruits, fruits)

paste(fruits, nfruits, sep = " = ")

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("red", colourStrings, value = TRUE)

colourStrings <- c("green", "blue", "orange", "red", "yellow", "lightblue", "navyblue", "indianred")
grep("^red", colourStrings, value = TRUE)

grep("red$", colourStrings, value = TRUE)

grep("r+", colourStrings, value = TRUE)

grep("e[2]", colourStrings, value = TRUE)
character(0)
grep("e{2}", colourStrings, value = TRUE)

gsub("red", "brown", colourStrings)
Okay na po salamat ng marami
 

Similar threads

Back
Top