Quickly reproduce data

I am new-ish to SO and I am curious how you quickly read in data from the questions people post. When someone posts an example data set that looks like this:

x=rnorm(100,0,1)
y=rnorm(100,0,1)
d=cbind(x,y)

I can quickly reproduce it in R. However, I often see people post example data that looks like:

df
   a b c d e f g h i j k l m n o
1  0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
2  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3  0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
4  0 1 1 0 0 0 1 0 0 0 0 0 0 0 0
5  0 1 0 0 1 1 0 0 0 1 1 0 0 1 0
6  0 1 0 0 1 1 0 0 0 0 0 1 1 0 0
7  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8  0 0 1 0 0 0 0 0 0 1 0 0 0 0 0
9  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
11 0 1 1 1 0 1 0 0 0 1 0 0 0 0 1
12 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0
13 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
14 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0
15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
16 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
17 0 1 0 1 1 1 0 0 0 0 0 1 1 1 0
18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
20 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0

and I have a hard time quickly reading this into R to answer their question..


I don't mean to divulge trade secrets, but you can also consider using soread() from the "overflow" package.

With it, you literally copy the sample dataset (ctrl + c) and type soread() and a data.frame named "mydf" would be created in your workspace.

library(overflow)
## Copy the relevant data, including the header
soread() ## can pass some other arguments, but this is generally enough

Example, with the data you shared:

library(overflow)
head(soread()) ## Just using `head` to minimize output
# data.frame “mydf” created in your workspace
#   a b c d e f g h i j k l m n o
# 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
# 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 3 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
# 4 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0
# 5 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0
# 6 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0

## Was the object really created?
ls()
# [1] "mydf"
head(mydf)
#   a b c d e f g h i j k l m n o
# 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
# 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 3 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
# 4 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0
# 5 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0
# 6 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0
链接地址: http://www.djcxy.com/p/24832.html

上一篇: Matlab:如何在保持标签信息的同时将我的数据矩阵分成两个随机的列向量子集?

下一篇: 快速重现数据