快速重现数据

时间:2015-03-25 13:55:37

标签: r

我是新手,我很好奇你如何快速阅读人们发布的问题数据。当有人发布如下所示的示例数据集时:

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

我可以在R中快速重现它。但是,我经常看到人们发布的示例数据如下:

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

我很难快速将其读入R以回答他们的问题。

1 个答案:

答案 0 :(得分:0)

我并不是要泄露商业机密,但您也可以考虑使用the "overflow" package中的soread()

有了它,你就可以复制样本数据集( ctrl + c )并输入soread()和名为“mydf”的data.frame在您的工作区中创建。

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

示例,包含您分享的数据:

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