3. Implementing Strings in R
3A) Write an R program to demonstrate use of various string manipulation functions. [Hint : paste(),nquote(),format(),cat(),toString(),sprint()]
# Example strings string1 <- "Hello" string2 <- "World!" number <- 42 # Using paste() function for string concatenation concatenatedString <- paste(string1, string2) cat("Using paste(): ", concatenatedString, "\n") # Using noquote() function to create a quoted expression quotedString <- noquote("This is a quoted string.") cat("Using noquote(): ", as.character(quotedString), "\n") # Using format() function for formatting strings formattedString <- format(number, scientific = TRUE) cat("Using format(): ", formattedString, "\n") # Using cat() function for printing multiple strings cat("Using cat(): ", string1, string2, "\n") # Using toString() function to convert variables to strings convertedToString <- toString(c("apple", "orange", "banana")) cat("Using toString(): ", convertedToString, "\n") # Using sprintf() function for formatted string output formattedOutput <- sprintf("The value of pi is approximately %.2f", pi) cat("Using sprintf(): ", formattedOutput, "\n")