How to transfer a table from the clipboard to a data.frame of R

3

Motivation

In many language questions R I see people putting the contents of a table instead of showing the steps to reproduce the data they are analyzing. Requests to supply the result of the dput command are simply ignored.

Having to type something like

dados <- data.frame(carat = c(0.230, 0.210) ...)

At all times it is tedious, subject to errors and a waste of time.

Question

How do I transfer the data from the table below to a data.frame using the clipboard? The famous Ctr-v

 carat cut       color clarity depth table price     x     y     z
 0.230 Ideal     E     SI2      61.5  55.0   326  3.95  3.98  2.43
 0.210 Premium   E     SI1      59.8  61.0   326  3.89  3.84  2.31
 0.230 Good      E     VS1      56.9  65.0   327  4.05  4.07  2.31
 0.290 Premium   I     VS2      62.4  58.0   334  4.20  4.23  2.63
 0.310 Good      J     SI2      63.3  58.0   335  4.34  4.35  2.75
 0.220 Fair      E     VS2      65.1  61.0   337  3.87  3.78  2.49
    
asked by anonymous 29.03.2018 / 19:46

1 answer

4

I believe there is a platform problem to import data with ctr-v , so here are two options:

For Windows users :

You can use the readClipboard() function for vectors. For example, entering data only from a row or column of a data frame.

For tabular data, simply use the read.table() function with clipboard as the file name:

read.table(file = "clipboard", head = TRUE)

Other systems :

I recommend the read.clipboard() function of the psych package:

psych::read.clipboard(head = TRUE)

Take a look at here for more package functions.

    
29.03.2018 / 20:41