Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy and paste data into R from the clipboard?

Tags:

io

clipboard

r

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?

like image 944
Moderat Avatar asked Nov 18 '12 01:11

Moderat


People also ask

How do I paste files from clipboard?

The Clipboard task pane holds many of the last images and text you copied or cut. Note: You can still do simple cut, copy, and paste the way you're used to, either by using the buttons on the ribbon or the keyboard shortcuts CTRL+X (Cut), CTRL+C (Copy), or CTRL+V (Paste).

How do I copy a datafile in R?

To copy a file in R, use the file. copy() method. The file. copy() function works in the same way as a file.


1 Answers

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") 

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) 
like image 185
bill_080 Avatar answered Sep 28 '22 06:09

bill_080