问题
我可以使用哪些应用函数从数据转到结果?
数据
start <- "My name is"
name.first <- c("John","Jane")
name.last <- c("Doe","Smith")
end <- "and I am a person."
期望的结果
result.1 <- c("My name is John Doe and I am a person",
"My name is Jane Doe and I am a person",
"My name is John Smith and I am a person",
"My name is Jane Smith and I am a person")
result.2 <- as.list(desired.1)
我微弱的尝试...
我认为mapply
可以在这里解决问题,但它只产生两个输出,而不是我想要的四个。
> mapply(function(x,y, start, end) paste(start, x, y, end, sep = " "),
+ name.first,
+ name.last,
+ MoreArgs = list(start, end),
+ USE.NAMES = FALSE)
[1] "My name is John Doe and I am a person."
[2] "My name is Jane Smith and I am a person."