所以我在保存我的推文时遇到了麻烦,当我收集它们并对其应用 sapply 时,它们以这种形式出现
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 ...
新更新:我尝试了你的方法 thomas,这不是我想要的,因为在我原来的 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() 类型略有变化。但我希望整个列表都是 chr[1:50] ,而不仅仅是一个。它也只有一个列表元素,不像我上面的原始 some_txt 。我真的希望有人可以帮助我>.<这让我很头疼