【发布时间】:2019-10-18 01:05:27
【问题描述】:
我有一个列表,我想迭代并在每个单词的末尾添加字符。但是,根据列表中的元素,我想更改要添加的单词。我也在寻找答案背后的一些直觉。最后,我正在使用 purrr 包中的函数式编程寻找答案。
#Here is the output without using purrr
my.list = list(first = c("AAPL", "MSFT"),
second = c("AMZN", "NFLX"))
paste(my.list[["first"]][1], ".O")
paste(my.list[["first"]][2], ".O")
paste(my.list[["second"]][1], ".P")
paste(my.list[["second"]][2], ".P")
Desired Output 将是一个这样的列表。
$first
"AAPL.O" "MSFT.O"
$second
"AMZN.P" "NFLX.P"
我列表中的第一个向量在向量中每个单词的末尾收到“.O”。 我列表中的第二个向量在每个单词的末尾收到“.P”。
谢谢。
【问题讨论】:
标签: r functional-programming purrr