首页 \ 问答 \ 在R中为N,Min / Max,SD,Mean和Median创建一个表格(Create a table for N, Min/Max, SD, Mean, and Median in R)

在R中为N,Min / Max,SD,Mean和Median创建一个表格(Create a table for N, Min/Max, SD, Mean, and Median in R)

我对R很新,所以请耐心等待这个基本问题。 我有一个使用data.table包创建的数据集DATA。 我在0到1之间创建了200个随机数,然后做了10000次,最后创建了一个数据表,用于每次迭代的描述性统计。 我的代码看起来像这样:

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]

数据看起来像这样:

    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
.    ...     ... 

等等

我想要做的是创建一个表格,找到累积样本均值的N,平均值,中位数,标准差,最小值和最大值(不是像上面那样每列的N)。 我需要输出看起来像这样:

   N     Mean   Median    SD    Min    Max
 10000  .502     .499    .280  .002   .999

我怎么能做到这一点?


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?


原文:https://stackoverflow.com/questions/16342261
更新时间:2024-03-27 21:03

最满意答案

你正在使用f.next(),它将返回下一行。 相反,你需要:

with open('/root/Desktop/test.txt', 'r+') as f:
    for line in f:
        found = line.find('Server version:')
        if found != -1:
            version = line[found+len('Server version:')+1:]
            print version

you are using f.next() which will return the next line. Instead you need:

with open('/root/Desktop/test.txt', 'r+') as f:
    for line in f:
        found = line.find('Server version:')
        if found != -1:
            version = line[found+len('Server version:')+1:]
            print version

相关问答

更多

相关文章

更多

最新问答

更多
  • Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)
  • C ++ 11 + SDL2 + Windows:多线程程序在任何输入事件后挂起(C++11 + SDL2 + Windows: Multithreaded program hangs after any input event)
  • AccessViolationException未处理[VB.Net] [Emgucv](AccessViolationException was unhandled [VB.Net] [Emgucv])
  • 计算时间和日期差异(Calculating Time and Date difference)
  • 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
  • C#对象和代码示例(C# objects and code examples)
  • 在python中是否有数学nCr函数?(Is there a math nCr function in python? [duplicate])
  • 检索R中列的最大值和第二个最大值的行名(Retrieve row names of maximum and second maximum values of a column in R)
  • 给定md5哈希时如何查找特定文件(How to find specific file when given md5 Hash)
  • Python字典因某些原因引发KeyError(Python Dictionary Throwing KeyError for Some Reason)
  • 如何让Joomla停止打开新标签中的每个链接?(How do I get Joomla to stop opening every link in a new tab?)
  • DNS服务器上的NS记录不匹配(Mismatched NS records at DNS server)
  • Python屏幕捕获错误(Python screen capture error)
  • 如何在帧集上放置div叠加?(How to put a div overlay over framesets?)
  • 页面刷新后是否可以保留表单(html)内容数据?(Is it possible to retain the form(html) content data after page refreshed?)
  • 使用iTeardownMyAppFrame和iStartMyAppInAFrame在OPA5测试中重新启动应用程序超时(Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out)
  • 自动拆分文本内容到列(Automatically splitting text content into even columns)
  • 在r中的循环中将模型名称分配给gbm.step(assigning model names to gbm.step in loop in r)
  • 昆明哪里有电脑等级考试二级C培训?
  • C ++模板实例化,究竟是什么意思?(C++ template instantiation, what exactly does it mean?)
  • 帮助渲染来自fields_for的部分内容(Help to render a partial from fields_for)
  • 将url.action作为json对象返回mvc(return url.action as json object mvc)
  • 使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
  • 将bindingRedirect添加到.Net标准库(Adding a bindingRedirect to a .Net Standard library)
  • Laravel版本升级会影响您的控制器吗?(Laravel version upgrade affects your controller?)
  • imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
  • 如何在eclipse debug impala前端
  • 如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])
  • 使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)
  • JS 实现一个菜单效果