概括性统计

mean {base}


Arithmetic Mean
算术平均

Description(描述)

    Generic function for the (trimmed) arithmetic mean.

    算术(截断)平均函数


Usage(用法)

    mean(x, ...)


## Default S3 method:   

默认S3方法:
     mean(x, trim = 0, na.rm = FALSE, ...)


Arguments(参数)
x  

    An R object. Currently there are methods for numeric/logical vectors and date, date-time and time interval objects. Complex vectors are allowed for trim = 0, only.
    一个R对象,目前有对数值/逻辑向量、日期、日期时间和时间间隔对象的算术平均方法。复数向量的方法仅仅在在trim=0时可以使用平均。

trim   

    the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. Values of trim outside that range are taken as the nearest endpoint.

    在计算平均值之前,从x的两端总共截断分数(0-0.5)倍数量的观测值。trim值之外范围的值被认为是最接近的终点。

na.rm    

    a logical value indicating whether NA values should be stripped before the computation proceeds.

    一个逻辑值,用于指定是否在计算之前把NA值剔除。
 ...  

    further arguments passed to or from other methods.

    更多参数,传递给其它方法或从其它方法传递过来的。


Value(返回值)

    If trim is zero (the default), the arithmetic mean of the values in x is computed, as a numeric or complex vector of length one. If x is not logical (coerced to numeric), numeric (including integer) or complex, NA_real_ is returned, with a warning.

    如果trim设定为0(默认情况),计算x的算术平均值,对于数值或复数向量返回值长度为1。如果x不是逻辑(强制转换为数值), 数值(包括整数)或复数,返回 NA_real_ ,并给出警告。

    If trim is non-zero, a symmetrically trimmed mean is computed with a fraction of trim observations deleted from each end before the mean is computed.

    如果trim非零,则计算对称截断算术平均值,计算之前先 从两边去掉tirm倍数量的观测值。


References(参考文献)

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.


 See Also(另见)

weighted.mean, mean.POSIXct, colMeans for row and column means.


Examples(示例)

x <- c(0:10, 50)
xm <- mean(x)
c(xm, mean(x, trim = 0.10))


参考(http://www.mathapply.cn/Applys/showpaper/pid/394)


sample {base}

[转载请注明出处,胡桃木屋 mathapply.cn ”R语言中文帮助“工作室译]


Random Samples and Permutations
随机样本和排列

Description(描述)
    sample takes a sample of the specified size from the elements of x using either with or without replacement.
     使用有回放或无回放的方式,从x的元素中抽取指定大小的一个样本。

Usage(用法)

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

Arguments (参数)
x
    Either a vector of one or more elements from which to choose, or a positive integer. See ‘Details.’
    不仅可以是用来抽样的包含一个或多个元素的向量,也可以是一个正整数。 见“详细说明”

n
     a positive number, the number of items to choose from. See ‘Details.’
    一个正数, 可抽取样本的项数。 见“详细说明”
size
     a non-negative integer giving the number of items to choose.
     一个正整数,用来确定抽取多少个样本。

replace
    Should sampling be with replacement?
    抽样是否可以有回放?

prob
    A vector of probability weights for obtaining the elements of the vector being sampled.
    被用来抽样的向量元素的一个概率权重的向量。

######################################################################

> sample(x=1:100,size=100,replace=TRUE)
  [1]  55  93   3  64  74  76  51  78  27   6  54  39  89  62  32  85   4   9
 [19]  44  85  60   7  69   4  98  55   4  16  65  29  49   2  67  50  58  66
 [37]  76  49  30  68  60  41  10  22  29  77 100  62  11  96   5   9   4   5
 [55]  59  52  26  57  85  29  78  75   6  44  37  84  51   2  34  12  47  99
 [73]  24  21   8  83   1  65  36  91   3  46  84  94  36  52  87  26  49  13
 [91]  57  51   7  63  82  57  85  72  19  86

表示用sample函数生成100个数,范围是1:100,replace表示抽取数可以重复
#######################################################################

#########################################

> y<-sample(x=1:100,size=100,replace=TRUE)
> y[sample(x=1:100,size=20,replace=TRUE)]<-NA
> y
  [1] 58 NA 71 47 89 NA NA 92 34  9 67 99 38 67 28 88 28 75 56 97  6 75  9 18 62
 [26] 61 29 27 19 NA  4 13 39 18 72 27 NA 98 26 88 38 85 63 71 27 19 35 78 67 NA
 [51]  6 NA 78 NA 46 22 32 96  4 57 NA 57 NA 76 52 22 56  2  3 NA 12 47 73 NA NA
 [76] 58 69 86 50  7 12 18  5 77 NA 29 43 92 62  4 14 45 53 59 20 NA 22 17 62 NA

>

表示随机抽取20个数,赋予空值NA 

###########################################

var(x):求x向量的方差

sqrt(z):开平方

sd(x):求标准差

min(x):求最小值

max(x):求最大值

median(x):求中位数

summary(x)::返回最大最小,中位数,分位数等详细信息

quantile(x,probs=c(0.25,0.75)):求x的1/4分位数跟3/4分位数


quantity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值