String in R
Any
values provided by the user in single quote ‘’ or double quotes “” compiler
treats as string
Syntax
firstname<-"Rupesh"
print(firstname)
String
Manipulation
·
paste() concatenates strings.
·
str_c() (or stringr) .
·
cat() prints and concatenates strings.
#Function without input/output
vectorVariable
<- c("Ram","Mohan","Shyam")
paste(vectorVariable,collapse="
")
cat(c("Primary","Secondary","Tersary"),
sep = "+")
Splitting
a string
·
strsplit splits the string using specific literal.
fullname<-"Rupesh.Kumar.Rupak"
strsplit(fullname,
"\\.")
#To
unlist the splitted values
unlist(strsplit(fullname,
"\\."))
Formatter
Syntax
format(x,
digits, nsmall, scientific, width, justify = c("left",
"right", "centre", "none"))
demoformat
<- format("WelcometoR", width = 8, justify = "c")
print(demoformat)
String in R
Reviewed by Rupesh
on
12:32
Rating:
No comments: