R语言 连接两个字符串 – paste()方法
R编程中的 paste() 方法用于通过分隔符来连接两个字符串的值。
语法: 粘贴(string1, string2, sep=)
返回: 返回串联后的字符串。
例1 :
# R program to concatenate two strings
# Given Strings
string1 <- "Geeks"
string2 <- "Geeks"
# Using paste() method
answer <- paste(string1, string2, sep=" For ")
print(answer)
输出
[1] "Geeks For Geeks"
例2 :
# R program to concatenate two strings
# Given Strings
string1 <- "I Love"
string2 <- "R programming"
# Using paste() method
answer <- paste(string1, string2, sep=" ")
print(answer)
输出
[1] "I Love R programming"
极客教程