Copy Data Frame to Clipboard in R (Example)

 

On this page, I’ll demonstrate how to copy a data frame to the clipboard in the R programming language.

The post contains these content blocks:

So now the part you have been waiting for – the example:

 

Creation of Example Data

To begin with, we’ll need to construct some data that we can use in the following example syntax.

data <- data.frame(x1 = 16:11,    # Create example data
                   x2 = "yyy",
                   x3 = LETTERS[10:15])
data                              # Print example data

 

table 1 data frame copy data frame clipboard

 

Table 1 shows that our example data contains six data points and three variables. The variable x1 is an integer and the variables x2 and x3 are characters.

 

Example: Copy Data Frame to Clipboard Using write_clip() Function

This example illustrates how to copy a data frame to the clipboard in the R programming language.

For this task, we can apply the write_clip function as shown below:

clipr::write_clip(data)           # Apply write_clip

After executing the previous R code, our data set is saved in the clipboard.

If we now press Ctrl + v, the following output is returned:

# x1	x2	x3
# 16	yyy	J
# 15	yyy	K
# 14	yyy	L
# 13	yyy	M
# 12	yyy	N
# 11	yyy	O

Looks good!

We may use this code to copy and paste our data to external files such as TXT, Excel, and CSV files.

 

Video & Further Resources

I have recently published a video on my YouTube channel, which shows the R programming codes of this article. You can find the video instruction below.

 

Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube Content Consent Button Thumbnail

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.

 

In addition, you might read some other R tutorials on this website:

 

At this point you should know how to copy a data set to the clipboard to write it to an external file in R programming. If you have additional questions and/or comments, please let me know in the comments section below. Furthermore, please subscribe to my email newsletter for updates on new articles.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top