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?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- What is the best way to do a search in a large fil
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
If you want to read in tabular data from a spreadsheet, I have used the following code
Look at the documentation for
?file
, sectionClipboard
:so, eg with magrittr:
There's an R package / RStudio plugin called
datapasta
that does this very neatly - see https://CRAN.R-project.org/package=datapasta. Image below is a demonstration of its simplicityA method that I've tested and works on both Windows and MacOS is to use
textConnection()
withread.table()
.First, paste your data into a variable as text:
Then, read the text string using read.table()
Not tested on Linux or other Unix systems, but I believe it should work cross-platform.
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:If you want to copy data from an R variable named
rdat
into the Windows clipboard (for example, to copy into Excel) use:Type in
data = as.numeric(read.table(text = "125 140 200 200 190 ", sep = " "))
where your numbers go in between thetext = " "
quotation marks.