From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vicente Vera Subject: Strings converted to numbers in Org table? Date: Fri, 24 Feb 2017 01:40:12 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1140a7a0901deb05493ccfab Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ch4ro-0006LG-Rp for emacs-orgmode@gnu.org; Thu, 23 Feb 2017 20:40:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ch4rn-0007wp-Lq for emacs-orgmode@gnu.org; Thu, 23 Feb 2017 20:40:16 -0500 Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:35088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ch4rn-0007vo-Fk for emacs-orgmode@gnu.org; Thu, 23 Feb 2017 20:40:15 -0500 Received: by mail-oi0-x22d.google.com with SMTP id 62so4408134oih.2 for ; Thu, 23 Feb 2017 17:40:13 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode --001a1140a7a0901deb05493ccfab Content-Type: text/plain; charset=UTF-8 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. --001a1140a7a0901deb05493ccfab Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello. I'm trying to get an Org table from an R data f= rame 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
=C2=A0 character vector).

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

-------= -----------------------

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

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

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

Here's = the output as seen in R:

: > tst
:=C2=A0=C2=A0 var1=C2=A0 var2=
: 1=C2=A0=C2=A0=C2=A0 a=C2=A0=C2=A0 150
: 2=C2=A0=C2=A0=C2=A0 b=C2= =A0=C2=A0 210
: 3=C2=A0=C2=A0=C2=A0 c=C2=A0=C2=A0 140
: 4=C2=A0=C2=A0= =C2=A0 d=C2=A0=C2=A0 150
: 5=C2=A0=C2=A0=C2=A0 e=C2=A0=C2=A0 192
: 6= =C2=A0=C2=A0=C2=A0 f=C2=A0=C2=A0 497
: 7=C2=A0=C2=A0=C2=A0 g 3.350
Details on the data frame:

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

It seems Org knows that the values on column "va= r2" 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.

--001a1140a7a0901deb05493ccfab--