all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Adding `sort' in R makes the output fail
@ 2014-10-23 14:37 Sebastien Vauban
       [not found] ` <alpine.OSX.2.00.1410230848520.460@charles-berrys-macbook.local>
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastien Vauban @ 2014-10-23 14:37 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello,

The following code does return a corrupted answer, while it's supposed
to return a sorted dataframe.

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC R :results value replace
con <- textConnection("
index	email
A	abc-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org
B	def-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org
C	def-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org
D	ghi-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org
E	abc-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org
F	def-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org")
df <- read.table(con, header = TRUE)
sort(table(df$email))
#+END_SRC

#+results:
| 1 |
| 2 |
| 3 |
--8<---------------cut here---------------end--------------->8---

See video at http://screencast.com/t/4u4Sj1Mkycwp to see the effect of
adding `sort', and see the output in RStudio (correct in both cases:
with and without `sort') on the right side of the video.

What's wrong here?

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Adding `sort' in R makes the output fail
       [not found]   ` <alpine.OSX.2.00.1410230848520.460-iDQ3frm8jJiryYnjg5slPZa4wMfmKMrbhPhL2mjWHbk@public.gmane.org>
@ 2014-10-23 18:49     ` Sebastien Vauban
  2014-10-23 20:04       ` Charles C. Berry
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastien Vauban @ 2014-10-23 18:49 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: public-emacs-orgmode-mXXj517/zsQ-wOFGN7rlS/M9smdsby/KFg



"Charles C. Berry" wrote:
> On Thu, 23 Oct 2014, Sebastien Vauban wrote:
>>
>> The following code does return a corrupted answer, while it's supposed
>> to return a sorted dataframe.
>
> Not so. See below.

So, that's RStudio that's wrong, in some way?

>> --8<---------------cut here---------------start------------->8---
>> #+BEGIN_SRC R :results value replace
>> con <- textConnection("
>> index	email
>> A	abc-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
>> B	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
>> C	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
>> D	ghi-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
>> E	abc-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
>> F	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org")
>> df <- read.table(con, header = TRUE)
>> sort(table(df$email))
>> #+END_SRC
>>
>> #+results:
>> | 1 |
>> | 2 |
>> | 3 |
>> --8<---------------cut here---------------end--------------->8---
>
> You created a `table' object, then you sorted it creating an `array' 
> object- an object of a different class.
>
> Is this what you want?
>
> #+BEGIN_SRC R :results value replace
> con <- textConnection("
> index	email
> A	abc-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
> B	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
> C	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
> D	ghi-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
> E	abc-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org
> F	def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org")
> df <- read.table(con, header = TRUE)
> as.table(sort(table(df$email)))
> #+END_SRC
>
> #+RESULTS:
> | ghi-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org | 1 |
> | abc-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org | 2 |
> | def-hcDgGtZH8xNBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org | 3 |

Yes, it is. Thanks!

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Adding `sort' in R makes the output fail
  2014-10-23 18:49     ` Sebastien Vauban
@ 2014-10-23 20:04       ` Charles C. Berry
  0 siblings, 0 replies; 3+ messages in thread
From: Charles C. Berry @ 2014-10-23 20:04 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



On Thu, 23 Oct 2014, Sebastien Vauban wrote:

> "Charles C. Berry" wrote:
>> On Thu, 23 Oct 2014, Sebastien Vauban wrote:
>>>
>>> The following code does return a corrupted answer, while it's supposed
>>> to return a sorted dataframe.
>>
>> Not so. See below.
>
> So, that's RStudio that's wrong, in some way?
>

Hmmm. Not exactly wrong.

There are a few wrinkles:

org-babel-R-write-object-command specifies a call to 
'write.table(object)', where `object' is what is to be printed.

`write.table' coerces whatever it is trying to print to a 
`data.frame'. See ?write.table

There is a method for `table' in `as.data.frame'. Try

  as.data.frame(table(1:3))

in the console or R gui to get a sense of what happens.

There is also an `array' method for `as.data.frame', but with a one 
dimensional array it passes control to the `vector' method. Try:

as.data.frame(sort(table(1:3)))

So it is really differences in the result of as.data.frame() that you were 
seeing.

I DK what RStudio does, but it must try harder a little harder to present 
1 dimensional arrays.

HTH,

Chuck

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

end of thread, other threads:[~2014-10-23 20:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23 14:37 Adding `sort' in R makes the output fail Sebastien Vauban
     [not found] ` <alpine.OSX.2.00.1410230848520.460@charles-berrys-macbook.local>
     [not found]   ` <alpine.OSX.2.00.1410230848520.460-iDQ3frm8jJiryYnjg5slPZa4wMfmKMrbhPhL2mjWHbk@public.gmane.org>
2014-10-23 18:49     ` Sebastien Vauban
2014-10-23 20:04       ` Charles C. Berry

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.