Formatted table output, printing into R console

心不动则不痛 提交于 2019-12-06 04:11:32

问题


I have function that processes some data and I would like to print the intermediate steps while the function (a loop) proceeds. I could do that in 1 point where the updated data is all in one data.frame(). I'm thinking of some simple table as for example I saw as part of Rapporter tool box.

So the question is how or whether it is possible to print table with numerical values into console.

Thanks.

EDIT: print() is not the solution I'm after and here is why:

function print() prints the numeric values into console, but its a messy bunch of numbers. I would like to have kind of table to easily check the values while the function proceeds. So I can better orientate in the numeric values.


回答1:


Something like this?

require(knitr)

for(i in 1:2){
  #some calculation 
  x<-runif(runif(1,1,5))
  y<-length(x)

  #dataframe output
  df <- cbind(x,y)

  #pretty table
  print(kable(df))
}


#output
#   |         x|  y|
#   |---------:|--:|
#   | 0.4872941|  3|
#   | 0.8014921|  3|
#   | 0.7023384|  3|
#   
#   
#   |         x|  y|
#   |---------:|--:|
#   | 0.9214315|  4|
#   | 0.7119830|  4|
#   | 0.0354769|  4|
#   | 0.1049139|  4|


来源:https://stackoverflow.com/questions/28895793/formatted-table-output-printing-into-r-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!