In: Computer Science
Discuss how to use R programming to solve the following problem. You’re not just writing the R code, you are also discussing the process.
Below is the R code. str_split() function is used to split the given string by space. The splitted string is now converted to list after split. Using the paste function separate words are again combined into the given format. The code will work for any 3 word string.
R Code-
name <- "Michael Carlos Dumas"
name
# Splitting the 3 words of name into 3 string
name <- strsplit(name, " ")
# Combining the names in given format using paste() function
new_name <- paste(name[[1]][1],
paste(substring(name[[1]][2],1,1),".",sep=""),name[[1]][3], sep = "
")
new_name
Code Screenshot-
Output-