样本修改 sample
Let’s understand one of the frequently used functions, sample() in R. In data analysis, taking samples of the data is the most common process done by the analysts. To study and understand the data, sometimes taking a sample is the best way and it is mostly true in case of big data.
让我们了解R中最常用的函数之一sample()。在数据分析中,对数据进行采样是分析师最常用的过程。 要研究和理解数据,有时取样是最好的方法,并且在大数据的情况下通常是正确的。
R offers the standard function sample() to take a sample from the datasets. Many business and data analysis problems will require taking samples from the data. The random data is generated in this process with or without replacement, which is illustrated in the below sections.
R提供了标准函数sample()来从数据集中获取样本。 许多业务和数据分析问题都需要从数据中取样。 随机数据是在此过程中生成的,有无替换,如下节所示。
Let’s roll into the topic!!!
让我们进入主题!!!
R中sample()的语法 (Syntax of sample() in R)
sample(x, size, replace = FALSE, prob = NULL)
- x – vector or a data set. x –向量或数据集。
- size – sample size. 大小 –样本大小。
- replace – with or without replacement of values. 替换 –替换或不替换值。
- replace – with or without replacement of values. 替换 –替换或不替换值。
- prob – probability weights 概率 –概率权重
更换样品 (Taking samples with replacement)
You may wonder, what is taking samples with replacement?
您可能想知道,正在取样替换的样品是什么?
Well, while you are taking samples from a list or a data, if you specify replace=TRUE or T, then the function will allow repetition of values.
好吧,当您从列表或数据中取样时,如果指定replace = TRUE或T ,则该函数将允许重复值。
Follow the below example which clearly explains the case.
请遵循以下示例,该示例清楚地说明了这种情况。