[英]calculate the median of intervals of a vector in R
I have the following challenge: Let X be a VA discrete evenly distributed in the interval [1, 10].我有以下挑战:让 X 是均匀分布在区间 [1, 10] 中的 VA 离散。 Be Y another VA each sample of Y is given by the median value of one set of 10 X samples.
是 Y 另一个 VA,Y 的每个样本由一组 10 个 X 样本的中值给出。 Generate 10^6 Y samples.
生成 10^6 Y 样本。
I'm using R, with the following code:我正在使用 R,代码如下:
x <- runif(10000000,1,10)
sample <- cut(x,breaks=10)
y = median(sample)
You could do:你可以这样做:
mosaic::median(~x|sample)
or in base R:或在基础 R 中:
tapply(x, sample, median)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.