Your chief concern seems to be making a reproducible example, so, in light of that, there are a couple solutions that come to mind.
The first is to use write.table
:
> write.table(iris, row.names=F)
"Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
5.1 3.5 1.4 0.2 "setosa"
4.9 3 1.4 0.2 "setosa"
4.7 3.2 1.3 0.2 "setosa"
The second is to use dput
:
> dput(iris[1:2, ])
structure(list(Sepal.Length = c(5.1, 4.9), Sepal.Width = c(3.5, 3), Petal.Length = c(1.4, 1.4), Petal.Width = c(0.2, 0.2), Species = structure(c(1L, 1L), .Label = c("setosa", "versicolor", "virginica"), class = "factor")), .Names = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"), row.names = 1:2, class = "data.frame")
Someone on StackOverflow could copy this output and assign it to a name:
> my.data <- structure(list(Sepal.Length = c(5.1, 4.9), Sepal.Width = c(3.5, 3), Petal.Length = c(1.4, 1.4), Petal.Width = c(0.2, 0.2), Species = structure(c(1L, 1L), .Label = c("setosa", "versicolor", "virginica"), class = "factor")), .Names = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"), row.names = 1:2, class = "data.frame")
> my.data
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
You should probably take a look at this question: How to make a great R reproducible example?