将数据框导出为R中的pdf / png

时间:2017-03-17 14:56:39

标签: r dataframe

以下是我的示例数据集:

Singer <- c("A","B","C","A","B","C")
Rank <- c(1,2,3,3,2,1)
Episode <- c(1,1,1,2,2,2)
Votes <- c(0.3,0.28,0.11,0.14,0.29,0.38)

Result <- data_frame(Episode,Singer,Rank,Votes)

我需要将数据框Result导出到图像,例如pdf或png。我试图将其打印并保存为pdf,但似乎有些列会被删除。我想知道是否有更简单的方法将数据帧导出到R中的图像。

1 个答案:

答案 0 :(得分:2)

如果要导出为png,可以这样做:

select 'Test_'
    + right(datepart(yy,GETDATE()),2)
    + RIGHT('0' + cast(datepart(m,getdate()) as varchar(2)),2)
    + RIGHT('0' + cast(datepart(d,getdate()) as varchar(2)),2)
    + '_'
    + RIGHT('0' + cast(datepart(HOUR,getdate()) as varchar(2)),2)
    + RIGHT('0' + cast(datepart(mi,getdate()) as varchar(2)),2)
    + '.txt.gpg'

如果您想以PDF格式导出,可以这样做:

library(gridExtra)
png("test.png", height = 50*nrow(df), width = 200*ncol(df))
grid.table(df)
dev.off()