如何获取 R 中的内置数据集列表?
How do I get a list of built-in data sets in R?
请问有哪位大侠能帮忙获取内置数据集列表及其依赖包吗?
有几种方法可以在 R 中找到包含的数据集:
1: 使用 data()
将为您提供所有已加载包的数据集列表(而不仅仅是来自 datasets
包的数据集) ;数据集按包排序
2: 使用 data(package = .packages(all.available = TRUE))
将为您提供计算机上可用包中所有数据集的列表(即未加载的包)
3: 使用 data(package = "packagename")
将为您提供该特定包的数据集,因此 data(package = "plyr")
将提供 plyr
中的数据集包裹
如果你想知道数据集位于哪个包中(例如acme
数据集),你可以这样做:
dat <- as.data.frame(data(package = .packages(all.available = TRUE))$results)
dat[dat$Item=="acme", c(1,3,4)]
给出:
Package Item Title
107 boot acme Monthly Excess Returns
我经常还需要知道哪些数据集结构可用,所以我在 misc package 中创建了 dataStr
。
dataStr <- function(package="datasets", ...)
{
d <- data(package=package, envir=new.env(), ...)$results[,"Item"]
d <- sapply(strsplit(d, split=" ", fixed=TRUE), "[", 1)
d <- d[order(tolower(d))]
for(x in d){ message(x, ": ", class(get(x))); message(str(get(x)))}
}
dataStr()
请注意控制台中的输出很长。
这是输出类型:
[...]
warpbreaks: data.frame
'data.frame': 54 obs. of 3 variables:
$ breaks : num 26 30 54 25 70 52 51 26 67 18 ...
$ wool : Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
$ tension: Factor w/ 3 levels "L","M","H": 1 1 1 1 1 1 1 1 1 2 ...
WorldPhones: matrix
num [1:7, 1:7] 45939 60423 64721 68484 71799 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:7] "1951" "1956" "1957" "1958" ...
..$ : chr [1:7] "N.Amer" "Europe" "Asia" "S.Amer" ...
WWWusage: ts
Time-Series [1:100] from 1 to 100: 88 84 85 85 84 85 83 85 88 89 ...
编辑:要获得更多信息输出并将其用于卸载的包或搜索路径上的所有包,请使用修改后的在线版本
source("https://raw.githubusercontent.com/brry/berryFunctions/master/R/dataStr.R")
运行
help(package = "datasets")
在 R Studio 控制台中,您将在右侧整洁的“帮助”选项卡中获得所有可用数据集。
这是一个由 Vincent Arel-Bundock 教授维护的综合 R 包数据集列表。
https://vincentarelbundock.github.io/Rdatasets/
Rdatasets
is a collection of nearly 1500 datasets that were originally
distributed alongside the statistical software environment R and some
of its add-on packages. The goal is to make these data more broadly
accessible for teaching and statistical software development.
请问有哪位大侠能帮忙获取内置数据集列表及其依赖包吗?
有几种方法可以在 R 中找到包含的数据集:
1: 使用 data()
将为您提供所有已加载包的数据集列表(而不仅仅是来自 datasets
包的数据集) ;数据集按包排序
2: 使用 data(package = .packages(all.available = TRUE))
将为您提供计算机上可用包中所有数据集的列表(即未加载的包)
3: 使用 data(package = "packagename")
将为您提供该特定包的数据集,因此 data(package = "plyr")
将提供 plyr
中的数据集包裹
如果你想知道数据集位于哪个包中(例如acme
数据集),你可以这样做:
dat <- as.data.frame(data(package = .packages(all.available = TRUE))$results)
dat[dat$Item=="acme", c(1,3,4)]
给出:
Package Item Title
107 boot acme Monthly Excess Returns
我经常还需要知道哪些数据集结构可用,所以我在 misc package 中创建了 dataStr
。
dataStr <- function(package="datasets", ...)
{
d <- data(package=package, envir=new.env(), ...)$results[,"Item"]
d <- sapply(strsplit(d, split=" ", fixed=TRUE), "[", 1)
d <- d[order(tolower(d))]
for(x in d){ message(x, ": ", class(get(x))); message(str(get(x)))}
}
dataStr()
请注意控制台中的输出很长。
这是输出类型:
[...]
warpbreaks: data.frame
'data.frame': 54 obs. of 3 variables:
$ breaks : num 26 30 54 25 70 52 51 26 67 18 ...
$ wool : Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
$ tension: Factor w/ 3 levels "L","M","H": 1 1 1 1 1 1 1 1 1 2 ...
WorldPhones: matrix
num [1:7, 1:7] 45939 60423 64721 68484 71799 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:7] "1951" "1956" "1957" "1958" ...
..$ : chr [1:7] "N.Amer" "Europe" "Asia" "S.Amer" ...
WWWusage: ts
Time-Series [1:100] from 1 to 100: 88 84 85 85 84 85 83 85 88 89 ...
编辑:要获得更多信息输出并将其用于卸载的包或搜索路径上的所有包,请使用修改后的在线版本
source("https://raw.githubusercontent.com/brry/berryFunctions/master/R/dataStr.R")
运行
help(package = "datasets")
在 R Studio 控制台中,您将在右侧整洁的“帮助”选项卡中获得所有可用数据集。
这是一个由 Vincent Arel-Bundock 教授维护的综合 R 包数据集列表。 https://vincentarelbundock.github.io/Rdatasets/
Rdatasets
is a collection of nearly 1500 datasets that were originally distributed alongside the statistical software environment R and some of its add-on packages. The goal is to make these data more broadly accessible for teaching and statistical software development.