x <- c(1,2,3) y <- c("A","B","C") x > 1 x < 3 y == "B" x < 3 & y == "B" x < 3 | y == "B" paste( "My","name","is","mud.") args( paste ) paste( "My","name","is","mud.", sep=":" ) paste( "My","name","is","mud.", sep="" ) paste0( "My","name","is","mud." ) a <- "mud." a paste("My","name","is", a ) # it can handle objects as arguments b <- c("Larry","Moe","Curly") b paste("My","name","is", b ) # it is vectorized data.frame( my="My", name="name", is="is", id=b ) data.frame( my="My", name="name", is="is", id=b ) paste( "id-", 1:10, sep="" ) c("This is a string.", "These", "words","are", "also", "strings." ) x <- c("This is a string.", "These", "words","are", "also", "strings." ) x x unlist( strsplit( x, " " ) ) unlist( strsplit( x, "" ) ) strsplit( x, " " ) unlist( strsplit( x, " " ) ) results <- strsplit( x, " " ) results length( x ) results <- strsplit( x, " " ) length( results[[1]] ) length( results ) lapply( results, length ) unlist( lapply( results, length ) ) results <- strsplit( x, "" ) lapply( results, length ) library( dplyr ) lapply( results, length ) %>% unlist() lapply( results, length ) z <- lapply( results, length ) z z <- lapply( results, length ) %>% unlist() z rbind( x, z ) cbind( x, z ) z <- lapply( results, length ) word.count <- lapply( strsplit( x, " " ), length ) char.count <- lapply( strsplit( x, "" ), length ) d <- data.frame( string=x, wc=word.count, cc=char.count ) d word.count <- lapply( strsplit( x, " " ), length ) %>% unlist() char.count <- lapply( strsplit( x, "" ), length ) %>% unlist() d <- data.frame( string=x, wc=word.count, cc=char.count ) d strings <- c("abcd", "cdab", "cabd", "c abd") strings grep( "ab", strings, value = TRUE ) grep("^ab", strings, value = TRUE) grep("ab$", strings, value = TRUE) grep("\\Bab", strings, value = TRUE) gsub( "land", "LAND", c("finland", "iceland", "michael landon") ) gsub( "\\bland", "LAND", c("finland", "iceland", "michael landon") ) gsub( "land$", "LAND", c("finland", "iceland", "michael landon") ) grepl( "\\bab", strings ) grepl( "\\bab", strings ) %>% sum() grepl( "\\bab", strings ) %>% mean() strings grep( "ab$", strings, value = FALSE ) strings <- c( "ht", "hot", "hoot", "hooot" ) grep("h*t", strings, value = TRUE) grep("h.t", strings, value = TRUE) grep("ho+t", strings, value = TRUE) grep("h+ot", strings, value = TRUE) grep("ho?t", strings, value = TRUE) grep("ho{2}t", strings, value = TRUE) grep("ho{2,}t", strings, value = TRUE) grep("ho{1,2}t", strings, value = TRUE) regexpr( "*", "abcd*efghi" ) grepl( "*", "abcd*efghi" ) grepl( "*", c("abcdefghi","abcd*efghi") ) grepl( "*", c("","abcdefghi","abcd*efghi") ) grepl( "\\*", c("","abcdefghi","abcd*efghi") ) my.text <- c( "FormA", "FormC", "FormE", "FormX", "FormY" ) grep( pattern="Form*", my.text ) grep( pattern="Form*", my.text, value=TRUE ) grep( pattern="Form[ABC]", my.text, value=TRUE ) my.text grep( pattern="Form[abc]", my.text, value=TRUE ) "a" == "A" args( grep ) grep( pattern="Form[abc]", my.text, value=TRUE, ignore.case=TRUE ) grep( pattern="Form[ABCabc]", my.text, value=TRUE ) grep( pattern="Form[A-C]", my.text, value=TRUE ) my.text <- c( "FormA", "FormB", "FormE", "FormX", "FormY" ) grep( pattern="Form[A-C]", my.text, value=TRUE ) grep( pattern="h[oi]t" , c("hot","hat","hit","hop") ) grep( pattern="h[oi]t" , c("hot","hat","hit","hop"), value=TRUE ) grep( pattern="g*fy", my.text, value=TRUE ) my.text <- c("micky","minnie","goofy","gofy","pluto") grep( pattern="g*fy", my.text, value=TRUE ) grep( pattern="pluo?to", my.text, value=TRUE ) grep( pattern="pluo?t", my.text, value=TRUE ) grep( pattern="plu?ot", my.text, value=TRUE ) grep( pattern="plo?to", my.text, value=TRUE ) grep( pattern="plu?o?to", my.text, value=TRUE ) grep( pattern="pl.to", my.text, value=TRUE ) my.text <- c("micky","minnie","goofy","gofy","pluto") grep( pattern="g.fy", my.text, value=TRUE ) grep( pattern="g.{2}fy", my.text, value=TRUE ) grep( pattern="g.{1,}fy", my.text, value=TRUE ) grep( pattern="g.{,1}fy", my.text, value=TRUE ) grep( pattern="g*{,1}fy", my.text, value=TRUE ) grep( pattern="mi*", my.text, value=TRUE ) URL <- "https://raw.githubusercontent.com/DS4PS/cpp-527-fall-2020/master/labs/data/medium-data-utf8.csv" d <- read.csv( URL ) grep( pattern="\\?", d$title, value=TRUE ) grep( pattern="\\?$", d$title, value=TRUE ) grep( pattern="\\B?", d$title, value=TRUE ) grep( pattern="\\B\\?", d$title, value=TRUE ) grep( pattern="\\B?", d$title, value=TRUE ) grep( pattern="\\B[?]", d$title, value=TRUE )