Articles - Importing & Exporting Data

Importing Data Sets Into R by Copying and Pasting

To import small data sets into R by copying and pasting, you can use the combination of the functions read.table() and textConnection().

For example:

Code R :
 
# Copy and paste small data set into an R object
small_dataset <- "cl   scl len ylabel_pos
1  0 chr13  56         56
2  0 chr17  96        152
3  1 chr13  34         34
4  1 chr17 166        200"
 
# Import the small data set into R data frame
df <- read.table(textConnection(small_dataset), header=TRUE)
print(df)
 


The imported data looks like this:

  cl   scl len ylabel_pos
1  0 chr13  56         56
2  0 chr17  96        152
3  1 chr13  34         34
4  1 chr17 166        200