如何在每个字的开头和结尾都不丢失“”字串的矢量

时间:2022-02-11 21:38:29

I want to get the line up data from this site; http://festileaks.com/pinkpop-festival/pinkpop-programma-2015/ , as input for a function.

我想从这个网站上获取数据;http://festileaks.com/pinkpop-festival/pinkpop-programma-2015/,作为函数的输入。

To use the data for my function I need it to be in a list. For this to work all the artists need to be between " " , which is the case in the vector of character strings. As soon as I collapse the vector into one string the "artist" changes into artist (without " "). Is there a way to get the artists into one list and not lose the " " ?

要使用函数的数据,我需要它在列表中。要使它工作,所有的艺术家都需要在“”之间,这是字符字符串的向量。一旦我把向量折叠成一个字符串,“艺术家”就变成了艺术家(没有“”)。有没有一种方法可以把艺术家放在一个列表中而不丢失“”?

This is the code I use (Rpackage rvest);

这是我使用的代码(Rpackage rvest);

Pinkpop_2015 <- read_html("http://festileaks.com/pinkpop-festival/pinkpop-          programma-2015/")
Pinkpophtml <- html_nodes(Pinkpop_2015, ".g7-one_third > a")
Pinkpoplineup <- html_text(Pinkpophtml)
Pinkpoplineup <- gsub("Â", "", Pinkpoplineup)
Pinkpoplineup <- gsub("-", "", Pinkpoplineup)
Pinkpoplineup <- gsub("^ ", '', Pinkpoplineup)

Plineup_string = paste(Pinkpoplineup, collapse=" ,")

1 个解决方案

#1


0  

Ok.. so based on your new character vector (I took just the first three occurrences):

好吧. .所以基于你的新角色向量(我只选了前三次):

Pinkpoplineup <- "Vrijdag 12 juni\n Muse\n Elbow"

You can try

你可以试着

Pinkpoplineup <- unlist(strsplit(Pinkpoplineup, split="\n "))

Pinkpoplineup  <- paste0('\"', Pinkpoplineup, '\"', collapse=",")

Quotes are now escaped and you can see the result using

引号现在被转义,您可以使用它来查看结果

cat(Pinkpoplineup)

or writing the object to a file

或者将对象写入文件

write(Pinkpoplineup, file = "Pinkpoplineup.txt")

#1


0  

Ok.. so based on your new character vector (I took just the first three occurrences):

好吧. .所以基于你的新角色向量(我只选了前三次):

Pinkpoplineup <- "Vrijdag 12 juni\n Muse\n Elbow"

You can try

你可以试着

Pinkpoplineup <- unlist(strsplit(Pinkpoplineup, split="\n "))

Pinkpoplineup  <- paste0('\"', Pinkpoplineup, '\"', collapse=",")

Quotes are now escaped and you can see the result using

引号现在被转义,您可以使用它来查看结果

cat(Pinkpoplineup)

or writing the object to a file

或者将对象写入文件

write(Pinkpoplineup, file = "Pinkpoplineup.txt")