Dear R users,
I need to export a data frame, and I would like to have all the columns perfectly aligned with the column names. At the time being, the output is not satisfactory.
Here below there is a real example, with the R commands that I am using.
Is it possible? How can I do?
place MDI MPI MOI mDO mPO mOO MDO MPO mDD mPD MDD MPD mDDD mPDD MDDD MPDD
Urbino 9 9 10 4 5 6 3 4 1 3 8 8 3 4 9 9
Jesi 12 13 14 7 7 9 4 7 3 4 7 9 5 5 10 11
Pesaro 10 13 14 7 6 9 5 9 3 2 6 10 7 6 8 12
Camerino 12 12 11 5 6 8 4 3 1 2 10 10 2 3 8 8
Ascoli 12 12 11 5 6 8 4 3 1 2 10 10 2 3 8 8
SBenedetto 12 12 11 5 6 8 4 3 1 2 10 10 2 3 8 8
....
place <- c("Urbino", "Jesi", "Pesaro", "Camerino", "Ascoli", "SBenedetto", "MteMonaco", "PSElpidio", "Ancona", "Osimo", "Montefano", "Fabriano", "Senigallia", "Macerata")
MAIL <- data.frame(place=place, MDI=max_dmo_ieri, MPI=max_prev_ieri, MOI=max_oss_ieri, mDO=min_dmo_oggi, mPO=min_prev_oggi, mOO=min_oss_oggi, MDO=max_dmo_oggi, MPO=max_prev_oggi, mDD=min_dmo_domani, mPD=min_prev_domani, MDD=max_dmo_domani, MPD=max_prev_domani, mDDD=min_dmo_dopodomani, mPDD=min_prev_dopodomani, MDDD=max_dmo_dopodomani, MPDD=max_prev_dopodomani)
write.table(MAIL, file="/home/meteo/KALMAN_DEV2/output/MAIL.txt", sep = "\t", row.names=FALSE, col.names = TRUE, quote=FALSE, qmethod="double")
Thank you for your help
Stefano Sofia
AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu? contenere informazioni confidenziali, pertanto ? destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si ? il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si ? ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell?art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessit? ed urgenza, la risposta al presente messaggio di posta elettronica pu? essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
Columns perfectly aligned with the column names
2 messages · Stefano Sofia, PIKAL Petr
Hi Your code is not reproducible but it probably does not matter. You use tab as separator which means the file is readable directly by spreadsheet programmes (Excel). Reading them as text shall be OK unless some values are not so long that they exceed predefined tabs or unless they have some leading spaces which are unseen but which cause unaligning. You can either read the file in Excel directly or to use some text formating tools (sprintf, formatC, ...) If you read it to Word, you also can change text to table whoch results in aligned values. Regards Petr
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Stefano Sofia
Sent: Monday, March 25, 2013 10:24 AM
To: r-help at r-project.org
Subject: [R] Columns perfectly aligned with the column names
Dear R users,
I need to export a data frame, and I would like to have all the columns
perfectly aligned with the column names. At the time being, the output
is not satisfactory.
Here below there is a real example, with the R commands that I am
using.
Is it possible? How can I do?
place MDI MPI MOI mDO mPO mOO MDO MPO
mDD mPD MDD MPD mDDD mPDD MDDD MPDD
Urbino 9 9 10 4 5 6 3 4
1 3 8 8 3 4 9 9
Jesi 12 13 14 7 7 9 4 7
3 4 7 9 5 5 10 11
Pesaro 10 13 14 7 6 9 5 9
3 2 6 10 7 6 8 12
Camerino 12 12 11 5 6 8 4
3 1 2 10 10 2 3 8 8
Ascoli 12 12 11 5 6 8 4 3
1 2 10 10 2 3 8 8
SBenedetto 12 12 11 5 6 8 4
3 1 2 10 10 2 3 8 8
....
place <- c("Urbino", "Jesi", "Pesaro", "Camerino", "Ascoli",
"SBenedetto", "MteMonaco", "PSElpidio", "Ancona", "Osimo", "Montefano",
"Fabriano", "Senigallia", "Macerata")
MAIL <- data.frame(place=place, MDI=max_dmo_ieri, MPI=max_prev_ieri,
MOI=max_oss_ieri, mDO=min_dmo_oggi, mPO=min_prev_oggi,
mOO=min_oss_oggi, MDO=max_dmo_oggi, MPO=max_prev_oggi,
mDD=min_dmo_domani, mPD=min_prev_domani, MDD=max_dmo_domani,
MPD=max_prev_domani, mDDD=min_dmo_dopodomani, mPDD=min_prev_dopodomani,
MDDD=max_dmo_dopodomani, MPDD=max_prev_dopodomani)
write.table(MAIL, file="/home/meteo/KALMAN_DEV2/output/MAIL.txt", sep =
"\t", row.names=FALSE, col.names = TRUE, quote=FALSE, qmethod="double")
Thank you for your help
Stefano Sofia
AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu? contenere
informazioni confidenziali, pertanto ? destinato solo a persone
autorizzate alla ricezione. I messaggi di posta elettronica per i
client di Regione Marche possono contenere informazioni confidenziali e
con privilegi legali. Se non si ? il destinatario specificato, non
leggere, copiare, inoltrare o archiviare questo messaggio. Se si ?
ricevuto questo messaggio per errore, inoltrarlo al mittente ed
eliminarlo completamente dal sistema del proprio computer. Ai sensi
dell?art. 6 della DGR n. 1394/2008 si segnala che, in caso di
necessit? ed urgenza, la risposta al presente messaggio di posta
elettronica pu? essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only
by persons entitled to receive the confidential information it may
contain. E-mail messages to clients of Regione Marche may contain
information that is confidential and legally privileged. Please do not
read, copy, forward, or store this message unless you are an intended
recipient of it. If you have received this message in error, please
forward it to the sender and delete it completely from your computer
system.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.