From: tsd@tsdye.com (Thomas S. Dye)
To: Rob Stewart <robstewart57@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: import R data frame into org-mode table
Date: Wed, 17 Jul 2013 12:48:00 -1000 [thread overview]
Message-ID: <m1fvvcu7kv.fsf@tsdye.com> (raw)
In-Reply-To: <CA+ZOasK8vN1dT_tVePVzOpTM3VdojoWCsvmhPZCzvV-k1CSjug@mail.gmail.com> (Rob Stewart's message of "Tue, 16 Jul 2013 16:19:07 +0100")
Rob Stewart <robstewart57@gmail.com> writes:
> I have an R script that generates a data frame, that I export to a CSV
> file. The data looks something like this:
>
> "","Variant","Xaxis","N","mean","sd","se"
> "1","line1",10,5,111.11,9.33,3.11
> "1","line1",20,5,112.11,9.13,3.14
> "1","line1",30,5,113.11,9.43,3.10
> "1","line2",10,5,101.11,8.33,2.11
> "1","line2",20,5,100.11,8.13,2.12
> "1","line2",30,5,108.11,8.03,2.10
>
> I have an ongoing org-mode document in which I'd like to report this
> data. I'd like to add a table that looks something like this:
>
> | Variant | X Axis | Y Axis | N | Mean | Standard Deviation |
> Standard Error |
> |----------------------------------------------------------------------------|
>
> The data will change frequently over the coming months. I'd like
> org-mode to auto-magically read a CSV file, to construct my org-table
> on-the-fly. I'd hoping to avoid copying and pasting results each time.
>
> Is there some org-mode or emacs+ESS magic I can use to populate my
> empty table, with source data from my CSV file?
>
> --
> Rob
Hi Rob,
Andreas' post answers your specific question.
In your situation, I typically don't run through a csv file, but just
write the R script so the data frame is returned to the Org mode buffer
as the result of the source code block.
As for the translation of column heads, see the ascii package for R,
which has a print() routine that recognizes Org mode as a type of
output, and which has facilities for formatting column names.
Here is an example from some work in progress that uses a session:
#+property: exports results
#+property: colnames yes
#+property: session *adzes*
#+name: lda-mid-z
#+header: :results output org
#+begin_src R
y <- edxrf[edxrf$lab=='UH-Hilo',]
fit <- lda(as.factor(site) ~ rb_ppm + sr_ppm + y_ppm + zr_ppm + nb_ppm,
data=y, na.action="na.omit", CV=TRUE)
adzes <- y$site=='unknown'
cap <- "Assignment of unknowns to sources"
z <- ascii(cbind(BPBM=y$bpbm[adzes],round(fit$posterior[adzes,],2)),header=T,include.colnames=T,caption=cap)
print(z,type="org")
rm(y,fit,adzes,cap,z)
#+end_src
#+RESULTS: lda-mid-z
#+BEGIN_ORG
#+CAPTION: Assignment of unknowns to sources
| BPBM | Haleakala | Kilauea | Mauna Kea | Nu`u | Pololu | Waiahole | unknown |
|---------------------------+-----------+---------+-----------+------+--------+----------+---------|
| 1985.134.01 adze | 0 | 0.1 | 0 | 0 | 0 | 0.64 | 0.27 |
| 50-HA-1349-G-5 adze | 0 | 0.85 | 0 | 0 | 0 | 0 | 0.14 |
| 50-HA-900-P24-1 microadze | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
...
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
prev parent reply other threads:[~2013-07-17 22:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-16 15:19 import R data frame into org-mode table Rob Stewart
2013-07-17 22:09 ` Andreas Leha
2013-07-29 14:42 ` Rob Stewart
2013-07-29 15:35 ` Cook, Malcolm
2013-07-29 16:03 ` John Hendy
2013-07-29 17:11 ` Nick Dokos
2013-07-29 20:17 ` Cook, Malcolm
2013-07-29 21:40 ` Nick Dokos
2013-07-30 17:59 ` Cook, Malcolm
2013-07-17 22:48 ` Thomas S. Dye [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1fvvcu7kv.fsf@tsdye.com \
--to=tsd@tsdye.com \
--cc=emacs-orgmode@gnu.org \
--cc=robstewart57@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).