如何在R中加载示例数据集? [英] How do I load example datasets in R?

查看:172
本文介绍了如何在R中加载示例数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想重现StackOverflow上发布的示例。有些人建议海报使用 dput()以帮助简化此过程或其中一个

然而,在这种情况下,假设我只给出了数据框的输出:

 > site.data 
网站年度峰值
1 ALBEN 5 101529.6
2 ALBEN 10 117483.4
3 ALBEN 20 132960.9
8 ALDER 5 6561.3
9 ALDER 10 7897.1
10 ALDER 20 9208.1
15 AMERI 5 43656.5
16 AMERI 10 51475.3
17 AMERI 20 58854.4

除了将其另存为文本文件并使用 read.table()

$ b还有其他选项吗? $ b

解决方案

这是一个方便的选项:

 网站。数据<  -  read.table(textConnection(
site year peak
1 ALBEN 5 101529.6
2 ALBEN 10 117483.4
3 ALBEN 20 132960.9
8 ALDER 5 6561.3
9 ALDER 10 7897.1
10 ALDER 20 9208.1
15 AMERI 5 43656.5
16 AMERI 10 51475.3
17 AMERI 20 58854.4))


Let's say I want to reproduce an example posted on StackOverflow. Some have suggested posters use dput() to help streamline this process or one of the datasets available in the base package.

In this case, however, suppose I have only been given the output of the dataframe:

> site.data
    site year     peak
1  ALBEN    5 101529.6
2  ALBEN   10 117483.4
3  ALBEN   20 132960.9
8  ALDER    5   6561.3
9  ALDER   10   7897.1
10 ALDER   20   9208.1
15 AMERI    5  43656.5
16 AMERI   10  51475.3
17 AMERI   20  58854.4

Do I have other options besides saving this as a text file and using read.table()?

解决方案

Here's one handy option:

site.data <- read.table(textConnection(
"        site year     peak
1  ALBEN    5 101529.6
2  ALBEN   10 117483.4
3  ALBEN   20 132960.9
8  ALDER    5   6561.3
9  ALDER   10   7897.1
10 ALDER   20   9208.1
15 AMERI    5  43656.5
16 AMERI   10  51475.3
17 AMERI   20  58854.4"))

这篇关于如何在R中加载示例数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆