当前位置:网站首页>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次方
边栏推荐
- [C language] Detailed explanation of custom types: structure, enumeration, union
- 【个人总结】2022.8.7周结
- textarea disable drag and drop
- R语言数据类型转换:基本数据类型的转换、将一种数据类型转化为另外一种数据类型
- 南非 KMP 媒体集团实施了 DMS(文档管理系统)使流程数字化,员工可以再次专注于他们的实际任务,提供了效率
- Server Configuration - Install Redis on Linux System
- 专访|360高瀚昭:ISC十年,360数字安全大脑能够“看见”什么?
- Knowledge points and written test questions related to shift operations, bit operations, and logical operations
- Three classic topics in C language: three-step flip method, Young's matrix, and tossing and dividing method
- MapStruct入门使用
猜你喜欢
Jenkins - install (2)
xxd命令(反编译、二进制文件转十六进制文件)
The programmer essential VS debugging technique
OpenInfra Days China 2022 |StreamNative 翟佳、刘德志受邀分享
MySQL:锁机制 |表级锁、行级锁 | 排它锁、共享锁 | 间隙锁
HackTheBox | Previse
ctfshow 七夕杯(复现)
MySQL:索引(1)原理与底层结构
干货满满,中科院信工所于静新课帮你get学术研究与论文写作技能
The use of string function, character function, memory function and its analog implementation
随机推荐
OFD是什么
(7)FlinkSQL将kafka数据写入到mysql方式二
curl获取harbor镜像仓库项目下的镜像列表
用 Antlr 重构脚本解释器
R语言patchwork包将多个ggplot2可视化结果组合起来、使用plot_annotation函数以及tag_level参数为组合图添加自定义编码序列(字符向量列表)
Background, History and Lessons of Transfer Learning
SSTI漏洞介绍认识(flask、Werkzeup)
win32&mfc————win32菜单栏&库
连锁小酒馆第一股,海伦司能否梦圆大排档?
【C语言】动态内存管理
(8)FlinkSQL自定义UDF
Jenkins - Introduction to Continuous Integration (1)
行业领先的界面开发组件DevExpress 8月发布新版——v22.1.4
[Redis] Redis installation and use of client redis-cli (batch operation)
【Rust—LeetCode题解】1.两数之和
深入浅出对话系统——任务型对话系统技术框架
Program Environment and Preprocessing
简析LDO静态电流与功耗的关系
MySQL:索引(1)原理与底层结构
【C语言】文件相关操作