1

I want to print the following in R:

f(x)
   1
   2
   3

I tried:

print(data.frame("f(x)" = 1:3), row.names = F)

However, the parentheses get converted to periods:

f.x.
   1
   2
   3

How can I print parentheses in column names? Of course, I could just write print("f(x)\n 1\n 2..."), but I need this to be from a data frame.

at.
  • 50,922
  • 104
  • 292
  • 461
  • 3
    `print(data.frame("f(x)" = 1:3, check.names = FALSE), row.names = F)` – Ronak Shah Oct 06 '20 at 02:50
  • The printing is fine. It's actually when you create the `data.frame` that the names are changed. This is because R tries to avoid column names that cannot be used as simple variable names. As already pointed out, you can turn that checking off with `check.names=FALSE` but using such column names can make things a lot messier depending on what you want to do with the data. – MrFlick Oct 06 '20 at 02:52
  • `check.names=F` is exactly what I was looking for, thank you! Add as an answer and I will credit it as such. – at. Oct 06 '20 at 02:57

0 Answers0