0

I like to use ascii output of my results.

There is always an extra 'h' in the header of my table which I and up removing manually.

I can not not figure out how to fix it in my code. See the code and result. E.g., how many cars have how many cilinders.

data(mtcars)
library(ascii)
ascii(as.data.frame(table(mtcars$cyl)),include.rownames=F,format='nice')


|================ 
h| Var1 h| Freq 
| 4    | 11   
| 6    | 7    
| 8    | 14   
|================ 

I would like to remove the extra h characters from the header. so that the output looks like this:

|================ 
| Var1 | Freq 
| 4    | 11   
| 6    | 7    
| 8    | 14   
|================ 

Is it a bug in ascii library or in my code? I want to do it via correct params of the ascii call rather then post processing the output, but would consider any "fix" if the proper solution is not possible.

2
  • 1
    I can't get it to produce the exact output without the h - but if you play around with storing your call to ascii into an object say tab <- ascii(your_stuff) then print(tab, type = "org") gives you something. I can't find the full list of types and I stumbled upon that in the examples for ascii. Commented May 30, 2012 at 15:41
  • From the documentation for ascii it looks like ascii(table(etc...)) should be sufficient. Have you tried that, in case it's as.data.frame which is sending some control character to ascii which is being misinterpreted? Commented May 30, 2012 at 16:07

1 Answer 1

2

It's not entirely obvious but the ascii.data.frame function takes a header argument that when set to FALSE will eliminate the undesired "h"s. There's also an include.colnames argument, should one want to get rid of what I would have called the "header".

> ascii(as.data.frame(table(mtcars$cyl)),include.rownames=F,header=FALSE,format='nice')
|============== 
| Var1 | Freq 
| 4    | 11   
| 6    | 7    
| 8    | 14   
|============== 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.