快速重现数据

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

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来回答他们的问题。


我并不是要泄露商业秘密,但你也可以考虑使用“overflow”包中的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
链接地址: http://www.djcxy.com/p/24831.html

上一篇: Quickly reproduce data

下一篇: How to easily combine data sets; how to quantify text data