在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
满意答案
你正在使用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
相关问答
更多如何一行一行或一整个文本文件读取?(How to read line by line or a whole text file at once?)
如何在Pig中的csv文件中读取下一行(how to read next line in csv file in Pig)
如何在Python中访问文件(.txt)中的下一行(How to access next line in a file(.txt) in Python)
如何在Python中将每行从文件读入列表中(How to read each line from a file into list word by word in Python)
如何在python文件的每一行上追加某些单词的任一侧的字符?(How do append characters on either side of certain words on every line in a file in python?)
只有当它以特定单词开头时才打印下一行(print next line only if it begins with a specific word)
Python - 仅在特定情况下读取文件的最后一行(Python - Only reading last line of file in specific circumstance)
如何从python文件中读取下一行或下一行的单词?(How to read next word or words till next line from file in python?)
从文件中读取单词并将其写入同一行(Reading Words from a File and Writing Them on The Same Line)
如何逐行读取python中的txt文件并将每一行设置为变量(How to read txt file in python line by line and set each line to a variable)
相关文章
更多Create a Bootable MicroSD Card
【转】异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅
nutch与起点R3集成之笔记(四)
nutch与起点R3集成之笔记(二)
Storm常见模式——求TOP N
Becoming a data scientist
在Hadoop集群上运行R程序--安装RHadoop
Guava集合工具类-Table接口映射处理
hibernate 1+N 问题
Guava学习笔记:Guava新集合-Table等
最新问答
更多如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
linux的常用命令干什么用的
由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
如何交换返回集中的行?(How to swap rows in a return set?)
在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
Java中的不可变类(Immutable class in Java)
WordPress发布查询(WordPress post query)
如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!