Skip to Content
R 语言经典实例(原书第 2 版)
book

R 语言经典实例(原书第 2 版)

by J.D. Long, Paul Teetor
June 2020
Beginner to intermediate
522 pages
9h 6m
Chinese
China Machine Press
Content preview from R 语言经典实例(原书第 2 版)
概率
213
rbinom(10, 1, 0.8)
#> [1] 1 0 1 1 1 1 1 0 1 1
8.7 随机排列向量
8.7.1 问题
你需要生成向量的随机排列。
8.7.2 解决方案
如果 v 是向量,则 sample(v) 返回 v 的一个随机排列。
8.7.3 讨论
这里把函数 sample 用于从大型数据集抽样。但是,该函数的默认参数使你可以创建一
个数据集的重新随机排列。函数调用 sample(v) 等效于:
sample(v, size = length(v), replace = FALSE)
这意味着“以随机顺序选定 v 的所有元素并且每个元素只使用一次”。这是一个随机排
列。以下是一个 1,,10 的随机排列:
sample(1:10)
#> [1] 7 3 6 1 5 2 4 8 10 9
8.7.4 另请参阅
有关 sample 函数的更多信息,请参见 8.5 节。
8.8 计算离散分布的概率
8.8.1 问题
你需要计算与离散随机变量相关的简单概率或累积概率。
8.8.2 解决方案
对于简单概率
P
(
X
x
),使用密度函数计算。所有 R 中的内置概率分布都有一个密度函
数,其函数名称为前缀“d ”加在分布名称前,例如,dbinom 是二项分布的密度函数。
对于累积概率
P
(
X
x
),使用分布函数计算。所有 R 中的内置概率分布都有一个分布函
214
8
数,其函数名称为前缀“p”加在分布名称前
因此,pbinom 是二项分布的分布函数。
8.8.3 讨论
假设我们有一个二项随机变量
X
,总试验次数为 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
大规模数据分析和建模:基于 Spark 与 R

大规模数据分析和建模:基于 Spark 与 R

Javier Luraschi, Kevin Kuo, Edgar Ruiz
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787111656814