[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Adding `sort' in R makes the output fail
From: |
Sebastien Vauban |
Subject: |
Re: [O] Adding `sort' in R makes the output fail |
Date: |
Thu, 23 Oct 2014 20:49:42 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (windows-nt) |
"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 address@hidden
>> B address@hidden
>> C address@hidden
>> D address@hidden
>> E address@hidden
>> F address@hidden")
>> 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 address@hidden
> B address@hidden
> C address@hidden
> D address@hidden
> E address@hidden
> F address@hidden")
> df <- read.table(con, header = TRUE)
> as.table(sort(table(df$email)))
> #+END_SRC
>
> #+RESULTS:
> | address@hidden | 1 |
> | address@hidden | 2 |
> | address@hidden | 3 |
Yes, it is. Thanks!
Best regards,
Seb
--
Sebastien Vauban