R 用等号粘贴两个字符串:"stringA" = "stringB"
R paste two string with an equal sign between it : "stringA" = "stringB"
我在 R 中有 2 个数组,
一个是
derive = c("excellent","bon","bad");
另一个是
couleurs = c("lightgreen","green","red");
我想要得到以下结果:
result = c("excellent"="lightgreen","bon"="green","bad"="red");
使用粘贴功能,我总是得到“”之间的全部结果,而“=”必须在“”之外。
我尝试使用 sep=' " " ' 但它创建了一个带有转义 "" 的字符串。
有什么想法吗?
谢谢
为此使用 names
:
derive <- c("excellent","bon","bad")
couleurs <- c("lightgreen","green","red")
result <- couleurs
names(result) <- derive
我在 R 中有 2 个数组,
一个是
derive = c("excellent","bon","bad");
另一个是
couleurs = c("lightgreen","green","red");
我想要得到以下结果:
result = c("excellent"="lightgreen","bon"="green","bad"="red");
使用粘贴功能,我总是得到“”之间的全部结果,而“=”必须在“”之外。
我尝试使用 sep=' " " ' 但它创建了一个带有转义 "" 的字符串。
有什么想法吗?
谢谢
为此使用 names
:
derive <- c("excellent","bon","bad")
couleurs <- c("lightgreen","green","red")
result <- couleurs
names(result) <- derive