当前位置:网站首页>sample function—R language
sample function—R language
2022-08-08 13:34:00 【Ah Qiangzhen】
简述:
Sample函数从xextracts a sample of the specified size from the elements of,with or without replacement.
其使用格式为:
sample函数
sample(x, size, replace = FALSE, prob = NULL)
其中:
- x:A selection of one or more elements of the vector,或一个正整数
- n:一个正数,Number of items to choose from.
- size:一个非负整数,Indicates the number of items available for selection
- replace:Sampling should be replaced
- prob:vector of probability weights used to obtain the elements of the sampled vector.
举例:
x <- 1:12
sample(x)
从1-12随机抽取12个元素,Equivalent to no back sample
sample(x,replace=T)
The output has duplicate values,Equivalent to sampling with replacement
y <- c(0,1)
sample(y,100,replace=T)
这里的100就是抽取100个元素,Because we're sampling with replacement here,So you can draw countless times
其他用法:
- Conditional extraction
比如抽取1到10中大于5的样本
sample(x[x > 5])
大于10的样本(Obviously one doesn't)
sample(x[x > 10])
输出整数0
但是注意!!!when you want output greater than9的样本的时候(很明显只有10)
Rlanguage is output10个向量
.这也是需要注意的一点
sample(x[x > 9])
If you really want to start from greater than9If extracted from the number of,需要使用sample.int函数
resample <- function(x, ...) x[sample.int(length(x), ...)]
resample(x[x > 8]) # length 2
resample(x[x > 9]) # length 1
resample(x[x > 10]) # length 0
The output is normal
sample.int函数
比如我想从1到1000randomly selected from time to time50个整数,有放回的抽样(可重复抽样)
sample.int(1e3, 100)
1e3代表1000,1en代表10的n次方
边栏推荐
- 家电行业趋势:2022从三方面把握家电产品升级方向
- (4)FlinkSQL将socket数据写入到mysql方式一
- 2020年是时候更新你的技术武器库了:Asgi vs Wsgi(FastAPI vs Flask)
- leetcode 155. Min Stack最小栈(中等)
- 【第2天】SQL快速入门-条件查询(SQL 小虚竹)
- 自动当道,效率至上 | 快来解锁财务共享服务中心数字化秘籍
- Fluorite, millet against smart camera
- 【JS高级】ES5标准规范之严格模式下的保护对象_09
- logistic回归模型—基于R
- 【Personal Summary】2022.8.7 Week End
猜你喜欢
The use of qsort function and its analog implementation
KMP Media Group South Africa implemented a DMS (Document Management System) to digitize the process, employees can again focus on their actual tasks, providing efficiency
Thesis understanding: "Self-adaptive loss balanced Physics-informed neural networks"
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
【C语言】文件相关操作
[C language] In-depth analysis of data storage in memory
连锁小酒馆第一股,海伦司能否梦圆大排档?
【个人总结】2022.8.7周结
南非 KMP 媒体集团实施了 DMS(文档管理系统)使流程数字化,员工可以再次专注于他们的实际任务,提供了效率
【C语言】动态内存管理
随机推荐
(7) FlinkSQL kafka data written to the mysql way 2
Server Configuration - Install Redis on Linux System
textarea 禁止拖拽
Tensorflow与Keras进行机器学习、深度学习
HackTheBox | Horizontall
SSTI漏洞介绍认识(flask、Werkzeup)
(7)FlinkSQL将kafka数据写入到mysql方式二
C语言小项目 -- 扫雷游戏完整代码(递归展开 + 选择标记)
The use of string function, character function, memory function and its analog implementation
【C语言】自定义类型详解:结构体、枚举、联合
2022-08-03
poj3744 Scout YYF I
R语言使用位置索引筛选dataframe的数据列:筛选单个数据列、筛选多个数据列、列表表达式方法、矩阵式下标方法
What is the IP SSL certificate, how to apply for?
sample函数—R语言
复盘:什么是秋招提前批?什么是普通秋招?都是招聘,为啥要设置这两个招聘时间段
KD-SCFNet:通过知识蒸馏实现更准确、更高效的显着目标检测(ECCV2022)
代码随想录笔记_动态规划_322零钱兑换
C language small project - complete code of minesweeper game (recursive expansion + selection mark)
Implement a customized pin code input control