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 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.
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.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
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.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.







4 Comments. Leave new
Is there any sentence to copy an output of a model? It will be very useful to get all the parameters by an export file.
Hello Diego,
After accessing the output components of the model, you can export them to an xlsx or csv file. Here is an example of exporting the linear regression coefficients to a csv file.
Best,
Cansu
Hi Cansu,
Maybe that came out wrong. For example, I would like to export an entire table of ANOVA avoid copy and paste from the console to and txt file or another extension file. I said ANOVA as an example, but maybe could be any output from a mixed model.
Thanks,
Diego
Hello Diego,
For Anova, it is slightly different. It is important to figure out the output object’s class; accordingly, you can convert it to a data frame and then use the exporting function of choice. See the following code for exporting Anova output.
Best,
Cansu