Character vectors¶
Beatles <- c("John", "Paul", "George", "Ringo")
Beatles
[1] "John" "Paul" "George" "Ringo"
paste("one","and","only")
[1] "one and only"
paste(Beatles, collapse=" & ")
[1] "John & Paul & George & Ringo"
First <- c("Mick","Keith","Ronnie","Charlie")
Last <- c("Jagger","Richards","Wood","Watts")
paste(First,Last)
[1] "Mick Jagger" "Keith Richards" "Ronnie Wood" "Charlie Watts"
paste(First,Last,sep="_")
[1] "Mick_Jagger" "Keith_Richards" "Ronnie_Wood" "Charlie_Watts"
Beatles <- c("John", "Paul", "George", "Ringo")
substr(Beatles,1,2)
[1] "Jo" "Pa" "Ge" "Ri"
substr(Beatles,1:4,2:5)
[1] "Jo" "au" "or" "go"
Led.Zeppelin.song <- "Whole Lotta Love"
ACDC.song <- sub("Love","Rosie",Led.Zeppelin.song)
print(ACDC.song)
[1] "Whole Lotta Rosie"
onetofour <- 1:4
names(onetofour) <- c("first","second","third","fourth")
names(onetofour)
[1] "first" "second" "third" "fourth"
onetofour
first second third fourth
1 2 3 4
print(onetofour)
first second third fourth
1 2 3 4
- R file: character-vectors.R
- Rmarkdown file: character-vectors.Rmd
- Jupyter notebook file: character-vectors.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):