我正在尝试将引号添加到列表中,该列表是从预测中输出的
recommenderlab
库。看起来如下图所示。我面对
将其转换为类似
List:
"Key"
"value1" "value2" "value3"
"value4" ..............
预期:
"value1", "value2", "value3", "value4" ..........
尝试了不同的方式
已使用:
stri_join_list(v_list, sep = ";", collapse = NULL)
library("recommenderlab")
data("MovieLense")
MovieLense100 <- MovieLense[rowCounts(MovieLense) >100,]
MovieLense100
train <- MovieLense100[1:50]
rec <- Recommender(train, method = "UBCF")
rec
pre <- predict(rec, MovieLense100[101:102], n = 10)
as(pre, "list")
当您在此处看到列表时,它将采用上述格式:
$`291`
[1] "Titanic (1997)" "Contact (1997)" "Alien (1979)"
[4] "Amadeus (1984)" "Godfather, The (1972)" "Aliens (1986)"
[7] "Sting, The (1973)" "American Werewolf in London, An (1981)" "Schindler's List (1993)"
[10] "Glory (1989)"
我希望它像:
"Titanic (1997)", "Contact (1997)", "Alien (1979)" ....
全部串联为一个字符串,就像上面的
谢谢,但
paste0(shQuote(list1),collapse =“,”)
上面的内容也不是我想要的,因为这给了我“ \”,请让我知道可以做什么
cat(paste0(shQuote(v_list [[“ bi_Marika77”]]),collapse =“;”))
-这有效。谢谢大家
但是,我在这里面临一个小挑战 想要将上述结果保留在数据帧中,其中第一列将是userid,第二列将是串联列表。请帮忙!
答案 0 :(得分:0)
我认为您正在寻找shQuote()
list1 = as(pre, "list")
paste0(shQuote(list1$`291`),collapse=",")