如何从剪贴板中将数据复制并粘贴到R中?

问题描述:

标题说明了一切:我在另一个应用程序(例如电子表格,如Excel或文本编辑器)中打开了我的数据。如果我将该数据复制到我的操作系统剪贴板,如何将其作为data.frame读入R?

The title says it all: I have my data open in another application (e.g., a spreadsheet, like Excel, or a text editor). If I copy that data to my operating system clipboard, how can I read it into R as a data.frame?

假设您在Windows剪贴板中有数据(例如,从Excel复制的数据),将该数据放入R使用中名为 copdat 的变量中:

Assuming you have data in the Windows clipboard (for example, copied data from Excel), to put that data into a variable named copdat in R use:

copdat <- read.delim("clipboard")

如果要将名为 rdat 的R变量中的数据复制到Windows剪贴板中(例如,要复制到Excel中),请使用:

If you want to copy data from an R variable named rdat into the Windows clipboard (for example, to copy into Excel) use:

write.table(rdat, "clipboard", sep="\t", row.names=FALSE, col.names=FALSE)