在R中创建N,Min / Max,SD,Mean和Median的表 [英] Create a table for N, Min/Max, SD, Mean, and Median in R
问题描述
我是R的新手,所以请在这个基本问题上忍受我。
我有一个数据集,DATA,我创建使用data.table包。我在0和1之间创建了200个随机数,然后是10000次,最后创建了一个数据表,用于每次迭代的描述性统计。我的代码看起来像这样:
rndm <-runif(200,min = 0,max = 1)
/ pre>
reps < - data.table(x = runif(200 * 10000),iter = rep(1:200,each = 10000))
DATA < ,中位数=中位数(rndm),sd = sd(rndm),min = min(rndm),
max = max(rndm)),by = iter]
数据看起来像这样:
SD最小最大
1 0.521 0.499 0.287 0.010 0.998
2 0.511 0.502 0.290 0.009 0.996
。 ... ...
等。
我想要做的是创建一个查找累积样本均值的N,平均值,中位数,标准偏差,最小值和最大值的表格(而不是上面的每一列)。我需要输出看起来像这样:
N平均中位数SD最小最大
10000 .502 .499。 280 .002 .999
我如何做到这一点?感谢您的帮助。
解决方案您还可以定义一个函数。
summaryfun < - function(x)list(N =长度(x),平均值=平均值(x),中值=中值(x),SD = sd(x),Min = min(x) )]
I'm very new to R, so please bear with me on this basic question. I have a dataset, DATA, that I created using the data.table package. I created 200 random numbers between 0 and 1, then did that 10000 times, finally creating a data table for with descriptive statistics for each iteration. My code for it looked like this:
rndm<-runif(200, min=0, max=1) reps <- data.table(x=runif(200*10000),iter=rep(1:200,each=10000)) DATA <- reps[,list(mean=mean(rndm),median=median(rndm),sd=sd(rndm),min=min(rndm), max=max(rndm)),by=iter]
The data looks something like this:
Mean Median SD Min Max 1 0.521 0.499 0.287 0.010 0.998 2 0.511 0.502 0.290 0.009 0.996 . ... ...
etc.
What I want to do is create a table that finds N, mean, median, standard deviation, minimum, and maximum of the accumulated sample means (not of each column like above). I need the output to look something like this:
N Mean Median SD Min Max 10000 .502 .499 .280 .002 .999
How can i accomplish this? Thank you for your help.
解决方案You could also define a function. This approach allows you to make the same table for a different variable.
summaryfun <- function(x)list(N=length(x),Mean=mean(x),Median=median(x),SD=sd(x),Min=min(x),Max=max(x)) DATA[,summaryfun(mean)]
这篇关于在R中创建N,Min / Max,SD,Mean和Median的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!