R(2) sample

sample: 从整体中挑出部分样本数据函数



Usage: sample.int(n, size = n, replace = FALSE, prob = NULL)

  • x:可以是R中任何?对象
  • size: 指定在向量中抽取元素的个数
  • replace:默认是F,表示每次?抽取后的数就不能在下一次被抽取;T表示抽取过的数可以继续拿来被抽取
  • prob:概率(probability),默认每一个元素被抽取的概率相等,称为随机抽样,实际中需要抽取的元素未必相等,则通过prob来指定

示例:

> sample(x=c("F","T"),size=10,replace = TRUE,prob = c(0.8,0.2))
 [1] "F" "F" "F" "F" "T" "F" "F" "T" "F" "F"

set.seed():  用于设定随机数种子 



   一个特定的种子可以产生一个特定的伪随机序列,这个函数的主要目的,是让你的模拟能够可重复出现,因为很多时候我们需要取随机数,但这段代码再跑一次的时候,结果就不一样了,如果需要重复出现同样的模拟结果的话,就可以用set.seed()

> set.seed(111)
> rnorm(3)
[1]  0.2352207 -0.3307359 -0.3116238
> set.seed(111)
> rnorm(3)
[1]  0.2352207 -0.3307359 -0.3116238

括号里的数只是一个编号而已,例如set.seed(100)不应将括号里的数字理解成“一百”,而是应该理解成“编号为一零零的随机数发生”,编号设定基本可以随意。

 pmax/pmin: p在这里表示parallel,可以理解为对向量进行平行比较



Usage:  pmax(..., na.rm = FALSE) /  pmin(..., na.rm = FALSE)

> x <- sample(c(1:10,NA),4)
>  x
[1]  3  1 10  4
>  pmax(x,5,na.rm = TRUE)
[1]  5  5 10  5
时间: 2024-10-13 17:09:01

R(2) sample的相关文章

R语言 sample抽样函数

Sample 函数用法: sample(x, size, replace = FALSE, prob = NULL) Arguments x - 可以是含有一个或多个元素的向量或只是一个正整数.x的长度为1时,那么便从1:x中抽取样本. size - 非负整数,从总体抽取样本的个数 replace - 是否有放回抽样 prob - 用于获得要采样的向量元素的概率权重向量. 原文地址:https://www.cnblogs.com/jiaxinwei/p/12316652.html

Basic linux command-with detailed sample

Here I will list some parameters which people use very ofen, I will attach the output of the command with one parameters as well. 1.   Create a new user:useradd Parameter:                                                                               

R in action读书笔记(13)第十章 功效分析

功效分析 功效分析可以帮助在给定置信度的情况下,判断检测到给定效应值时所需的样本量.反过来,它也可以帮助你在给定置信度水平情况下,计算在某样本量内能检测到给定效应值的概率.如果概率低得难以接受,修改或者放弃这个实验将是一个明智的选择. 10.1假设检验速览 在研究过程时,研究者通常关注四个量:样本大小.显著性水平.功效和效应值.样本大小指的是实验设计中每种条件/组中观测的数目.显著性水平(也称为alpha)由I型错误的概率来定义.也可以把它看做是发现效应不发生的概率.功效通过1减去II型错误的概

Sampling Distributions and Central Limit Theorem in R(转)

The Central Limit Theorem (CLT), and the concept of the sampling distribution, are critical for understanding why statistical inference works. There are at least a handful of problems that require you to invoke the Central Limit Theorem on every ASQ

代写statistical R 程序、代做留学生R统计作业

代写statistical R 程序.代做留学生R统计作业1. This is a take-home final exam.2. Answers to Questions 1,2,3,4 should be written using a Latex editor. Question 5 can beanswered using your preferred program. All answers should be merged in a single PDF andsubmitted i

皮尔逊相关系数(Pearson Correlation Coefficient, Pearson&#39;s r)

Pearson's r,称为皮尔逊相关系数(Pearson correlation coefficient),用来反映两个随机变量之间的线性相关程度. 用于总体(population)时记作ρ (rho)(population correlation coefficient): 给定两个随机变量X,Y,ρ的公式为:  其中:   是协方差 是X的标准差 是Y的标准差 用于样本(sample)时记作r(sample correlation coefficient): 给定两个随机变量x,y,r的公

吴裕雄--天生自然 R语言开发学习:功效分析

#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # requires packages pwr to be installed # # install.packages("pwr") # #----------------------------------------# par(ask=TRUE) library(pwr) # t te

吴裕雄--天生自然 R语言开发学习:功效分析(续一)

#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # requires packages pwr to be installed # # install.packages("pwr") # #----------------------------------------# par(ask=TRUE) library(pwr) # t te

智原GM推出GM8126升级产品GM8138

Rescue Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task is: