Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retain date/time format in xtable for an email

I am looking to email a nicely formatted table from R using xtable. I found this thread explaining how to email an xtable easily, which works and the table looks great. However each time I do my date/time columns convert to numeric.

My email code:

body=print(xtable(myData), type="html")

My dates convert from YYYY-MM-DD hh:mm:ss to numeric (e.g. 1508117307.17). I've tried a number of ways to try to convert it back using things like transform and as.Date(), but no matter what I do the dates still convert to numeric.

Is it possible to coerce xtable to retain my original date/time format?

Thank you!

like image 829
Jamison Avatar asked Oct 29 '25 13:10

Jamison


1 Answers

Convert the date to character using as.character() before printing the table should do the job.

Disclaimer: I moved this answer here from the comments so other users can make use of the solution.

like image 82
tobiasegli_te Avatar answered Oct 31 '25 04:10

tobiasegli_te



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!