Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatted table output, printing into R console

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.

like image 996
Maximilian Avatar asked Mar 06 '15 09:03

Maximilian


1 Answers

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|
like image 109
zx8754 Avatar answered Sep 30 '22 03:09

zx8754