所以我在保存推文时遇到了麻烦,当我收集它们并在它们上面应用时,它们会以这种形式出现
some_txt = sapply(tweets, function(x) x$getText())
[1] "RT @JanoImLukesSlut: #HarryHas17MillionFollowParty\n♔ RT\n♔Follow me\n♔Ask4follow back\n♔Follow ALL who RTs\n♔Gain\n♔Drink pepsi feel sexyyy\n#Sto…"
[2] "RT @abria_valerie: Pepsi is like crack to me. I gotta have it."
[3] "@JLinn6 having to stop for dr. Pepper bc someone doesn't like Pepsi. #picky #spoiledbrat #watchoutonlylikesdr.'s"
[4] "RT @cyberscott1975: The coca cola truck can bugger off! I want a Pepsi Max Xmas Truck!í ½íºš"
[5] "í ½í²•í ½í²•í ½í²•Mmm That Spicy Chicken Sandwich And Fries And Pepsi From Wendy's Was A1í ½í²¦"
[6] "@JatnnaP05 @Alexandergr_ @IannErnesto @WilberJE ENTRA dale a GALERIA luego vota por : attabeira https://t.co/hh0Q5tkHzx #HelpMe"
[7] "RT @supersunnytime: wallowing in a sea of pop punk and self-hatred"
[8] "These bitches love soda Pepsi and Cola"
[9] "RT @Lmao: waiter: \"what drink would you like\" \nme: \"тнє вℓσσ∂ σƒ му єηємιєѕ\" \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \"is pepsi o…"
.......................
然而,当我对它应用写csv时。然后把它读回去它不会回来相同的格式
write.csv(some_txt, file = file.choose(), row.names = TRUE, sep = ',', col.names = TRUE)
some_txt = read.csv(file.choose(), row.names = 1, sep = ',')
它取而代之的是
x
1 RT @JanoImLukesSlut: #HarryHas17MillionFollowParty\n♔ RT\n♔Follow me\n♔Ask4follow back\n♔Follow ALL who RTs\n♔Gain\n♔Drink pepsi feel sexyyy\n#Sto…
2 RT @abria_valerie: Pepsi is like crack to me. I gotta have it.
3 @JLinn6 having to stop for dr. Pepper bc someone doesn't like Pepsi. #picky #spoiledbrat #watchoutonlylikesdr.'s
4 RT @cyberscott1975: The coca cola truck can bugger off! I want a Pepsi Max Xmas Truck!í ½íºš
5 í ½í²•í ½í²•í ½í²•Mmm That Spicy Chicken Sandwich And Fries And Pepsi From Wendy's Was A1í ½í²¦
6 @JatnnaP05 @Alexandergr_ @IannErnesto @WilberJE ENTRA dale a GALERIA luego vota por : attabeira https://t.co/hh0Q5tkHzx #HelpMe
7 RT @supersunnytime: wallowing in a sea of pop punk and self-hatred
8 These bitches love soda Pepsi and Cola
9 RT @Lmao: waiter: "what drink would you like" \nme: "тнє вℓσσ∂ σƒ му єηємιєѕ" \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \nme: \nwaiter: "is pepsi o…
......
有关如何将其返回相同值的任何想法?我正在使用csv,因为我想手动收集这些推文。
这是some_txt的str()示例(它的50条推文就是为什么它的1:50)
chr [1:50] "@psychicpebble AMEN THANK YOU FOR NOT TALKING ABOUT THAT PEPSI SHIT." ...
编辑:
这是读取(示例)
后输出的str()示例 'data.frame': 50 obs. of 1 variable:
$ x: Factor w/ 43 levels "$39 = Jack'n'Coke, Vodka & Pepsi, and a 24 oz. Miller Lite. Fml.",..: 10 24 33 9 13 39 9 21 6 31 ...
新更新: 我试过你的方法托马斯,这不是我想要的,因为在我原来的some_txt我可以做到这一点
> some_txt[2]
[1] "RT @Nada_7Q: #تابعني_اتابعك\n@toomy48\n@m_alzuhair\n@alzheri33 \n@hallm77\n@tooomy48\n@RT_FAEF\n@Nada_7Q★☆★☆\n@abosaef11\n@adoan3\n@Msolfje\n@Khalid_06…"
> some_txt[1]
[1] "RT @CodeClue: 50 CL Pepsi is unnecessary tbh."
> some_txt[3]
[1] "I just ate all my Dad's very expensive cheese and it's supposed to be eaten slowly with a nice glass of red not a Pepsi Max"
将stringAsFactor应用于read.csv之后,它仍会打印出相同的内容,但是str()类型稍有改变。但我希望整个列表都是[1:50],而不仅仅是单个列表。 此外,它只有一个列表元素,不像我上面的原始some_txt。 我真的希望有人可以帮助我>。<这让我很头疼
答案 0 :(得分:0)
这就是我把它放回原始形式列表中所做的。
for(i in 1:length(some_txt[,1])){
some_txt1 = c(some_txt1,some_txt[,1][i])
}
我只是基本上创建一个for循环,然后将它们循环回列表。