A character
object in R represents string of characters.
> name <- "Krishna" > ls() [1] "clc" "name" > eapply(.GlobalEnv,typeof) $name [1] "character" $clc [1] "closure"
ls() returns
what data sets and functions are defined.
Converts objects to character
You can
convert other objects like numbers to character by using as.character()
function.
> revenue=25.34 > revenueChar=as.character(revenue) > revenueChar [1] "25.34"
Concatenate two character objects
You can
concatenate two character objects using paste function.
> firstName <- "Hari krishna" > lastName <- "Gurram" > fullName <- paste(firstName, lastName) > fullName [1] "Hari krishna Gurram"
Extracting substring from character object
You can
extract sub string from character object using substr method.
> substr("Welcome to R Language", start=14, stop=21) [1] "Language"
No comments:
Post a Comment