emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Strings converted to numbers in Org table?
@ 2017-02-24  1:40 Vicente Vera
  2017-02-27 13:49 ` Vicente Vera
  0 siblings, 1 reply; 7+ messages in thread
From: Vicente Vera @ 2017-02-24  1:40 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

Hello. I'm trying to get an Org table from an R data frame but data is
lost in the process.

Here is a MWE. Note that:

- In R every value is a string. "var2" contains no numbers (is a
  character vector).

- Upon conversion to a table Org removes the zero from "var2" last
  value.

------------------------------

#+BEGIN_SRC R :session *mwe* :results value table :colnames yes
  tst <- data.frame(var1 = c("a", "b", "c", "d", "e", "f", "g"),
                    var2 = c("150", "210", "140", "150", "192", "497",
"3.350"),
                    stringsAsFactors = FALSE)
  tst
#+END_SRC

#+RESULTS:
| var1 | var2 |
|------+------|
| a    |  150 |
| b    |  210 |
| c    |  140 |
| d    |  150 |
| e    |  192 |
| f    |  497 |
| g    | 3.35 |

------------------------------

Here's the output as seen in R:

: > tst
:   var1  var2
: 1    a   150
: 2    b   210
: 3    c   140
: 4    d   150
: 5    e   192
: 6    f   497
: 7    g 3.350

Details on the data frame:

: > str(tst)
: 'data.frame':    7 obs. of  2 variables:
:  $ var1: chr  "a" "b" "c" "d" ...
:  $ var2: chr  "150" "210" "140" "150" ...

It seems Org knows that the values on column "var2" are numbers and
converts the strings to numbers, applying some obscure trimming on the
digits. The "3.350" value needs to be left as is.

[-- Attachment #2: Type: text/html, Size: 1883 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-02-28  7:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-24  1:40 Strings converted to numbers in Org table? Vicente Vera
2017-02-27 13:49 ` Vicente Vera
2017-02-27 15:31   ` Vicente Vera
2017-02-27 17:33     ` Nicolas Goaziou
2017-02-27 19:20       ` Vicente Vera
2017-02-27 18:17     ` Charles C. Berry
2017-02-28  7:43       ` Alan Schmitt

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).