在单张xlsx文件中附加r输出 [英] Appending r output in a single sheet of xlsx file

查看:49
本文介绍了在单张xlsx文件中附加r输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的R输出附加到一张xlsx文件中?我目前正在进行网络抓取,其中我需要从网站上抓取用户评论,并将其以xlsx格式保存在我的桌面停顿中.我每次都需要在代码中更改网站网址(因为用户评论位于不同的页面中),并将输出保存在一张xlsx文件中.

How can i append my R outputs in a single sheet of xlsx file? I am currently working on web crawling wherein i need to scrap the user reviews from website and save it in my deskstop in xlsx format. I need to every time change the website url(as user reviews are in different pages) in my code and save the output in one sheet of xlsx file.

您能帮我在一张xlsx文件中附加输出的代码吗?下面是我正在使用的代码:每当我需要更改网站URL并运行下面的相同代码并将相应的输出保存在mydata.xlsx

Can you please help me with the code of appending outputs in a single sheet of xlsx file? Below is the code which i am using: Every time i need to change the website url and run the same below code and save the corresponding output in a single sheet of mydata.xlsx

library("rvest")
htmlpage <- html("http://www.glassdoor.com/GD/Reviews/Symphony-Teleca-Reviews-E28614_P2.htm?sort.sortType=RD&sort.ascending=false&filter.employmentStatus=REGULAR&filter.employmentStatus=PART_TIME&filter.employmentStatus=UNKNOWN")
proshtml <- html_nodes(htmlpage, ".pros")
pros <- html_text(proshtml)
pros

data=data.frame(pros)

library(xlsx)
write.xlsx(data, "D:/mydata.xlsx", append=TRUE)

推荐答案

查看包 xlsx .

?write.xlsx 将显示您想要的内容. append = TRUE 是关键.

?write.xlsx will show you what you want. append=TRUE is the key.

=========编辑正确=========

正如@Jakub指出的那样, append = TRUE 将另一个工作表添加到文件中.

As @Jakub pointed out, append=TRUE adds another worksheet to the file.

=========另一种方法==========

另一种方法是将数据保存到 .csv 文件,该文件可以从excel中轻松打开.在这种情况下, append = T 可以按预期工作(添加到现有工作表中):

Another method is to save the data to a .csv file, which could easily open from excel. In this case, the append=T works as expected (adding to the existing sheet):

write.table(df,"D:/MyFile.csv",append=T,sep=",")

这篇关于在单张xlsx文件中附加r输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆