Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Hadley Wickham
> | but they won't receive any new
> | features, and we believe that there
> | are now better approaches to solving
> | the same problem.
>
> Is tidyr::pivot_longer this better
> solution?  It is an easier to understand
> version of the now retired and confusing
> (for me) tidyr::gather which at least
> reigned back in 2018 (was that any good
> compared to reshape?).

Yes, and hopefully :)

library(tidyr)

tab <- structure(list(
date = c("2019M08", "2019M09", "2019M10"),
down = c(0.01709827, 0.02094724, 0.01750911),
uc = c(0.2653882, 0.2265797, 0.245003),
up = c(0.7175136, 0.7524731, 0.7374879)),
class = "data.frame", row.names = c(NA, -3L))

tab %>% pivot_longer(
  down:up,
  names_to = "direction",
  values_to = "percentage"
)
#> # A tibble: 9 x 3
#>   datedirection percentage
#>
#> 1 2019M08 down  0.0171
#> 2 2019M08 uc0.265
#> 3 2019M08 up0.718
#> 4 2019M09 down  0.0209
#> 5 2019M09 uc0.227
#> 6 2019M09 up0.752
#> 7 2019M10 down  0.0175
#> 8 2019M10 uc0.245
#> 9 2019M10 up0.737

Created on 2020-08-17 by the [reprex
package](https://reprex.tidyverse.org) (v0.3.0)



-- 
http://hadley.nz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Rasmus Liland
On 2020-08-17 10:09 -0700, Bert Gunter wrote:
| On Mon, Aug 17, 2020 at 9:53 AM Rasmus Liland wrote:
| |
| | Also, stack is also possible to use:
| |
| | tab <- structure(list(
| | date = c("2019M08", "2019M09", "2019M10"),
| | down = c(0.01709827, 0.02094724, 0.01750911),
| | uc = c(0.2653882, 0.2265797, 0.245003),
| | up = c(0.7175136, 0.7524731, 0.7374879)),
| | class = "data.frame", row.names = c(NA, -3L))
| |
| | out <- utils::stack(x=tab, select=-date)
| | colnames(out) <- c("percentage", "direction")
| | out$date <- tab$date
| | out <- out[,sort(colnames(out))]
| 
| Well, not that there is anything 
| "wrong" with previous suggestions, but 
| it is pretty straightforward just with 
| base R functionality:
| 
| > nm <- names(tab)[2:4]
| > with(tab, data.frame(date = rep(date, length(nm)),
| +  direction = rep(nm, e = 3),
| +  percentage = do.call(c, tab[, nm]))
| +  )

This is good :)  You can also use unlist 
directly instead of do.call(c, ...)

nm <- names(tab)[2:4]
data.frame(
  date=tab$date,
  direction=rep(nm, each=length(nm)),
  percentage=unlist(tab[,nm]))

V

r


signature.asc
Description: PGP signature
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Bert Gunter
Well, not that there is anything "wrong" with previous suggestions, but it
is pretty straightforward just with base R functionality:

> nm <- names(tab)[2:4]
> with(tab, data.frame(date = rep(date, length(nm)),
+ direction = rep(nm, e = 3),
+ percentage = do.call(c, tab[, nm]))
+ )
 date direction percentage
down1 2019M08  down 0.01709827
down2 2019M09  down 0.02094724
down3 2019M10  down 0.01750911
uc1   2019M08uc 0.26538820
uc2   2019M09uc 0.22657970
uc3   2019M10uc 0.24500300
up1   2019M08up 0.71751360
up2   2019M09up 0.75247310
up3   2019M10up 0.73748790


Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Aug 17, 2020 at 9:53 AM Rasmus Liland  wrote:

> Dear John,
>
> Op ma 17 aug. 2020 om 09:52 schreef Eric Berger:
> | On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx wrote:
> | |
> | | You are looking for tidyr::pivot_longer()
> |
> | Alternatively, melt() from the reshape2 package.
> |
> | library(reshape2)
> | melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
> | ="direction",value.name="percentage")
>
> Also, stack is also possible to use:
>
> tab <- structure(list(
> date = c("2019M08", "2019M09", "2019M10"),
> down = c(0.01709827, 0.02094724, 0.01750911),
> uc = c(0.2653882, 0.2265797, 0.245003),
> up = c(0.7175136, 0.7524731, 0.7374879)),
> class = "data.frame", row.names = c(NA, -3L))
>
> out <- utils::stack(x=tab, select=-date)
> colnames(out) <- c("percentage", "direction")
> out$date <- tab$date
> out <- out[,sort(colnames(out))]
>
> out
>
> yields
>
>  date direction percentage
> 1 2019M08  down 0.01709827
> 2 2019M09  down 0.02094724
> 3 2019M10  down 0.01750911
> 4 2019M08uc 0.26538820
> 5 2019M09uc 0.22657970
> 6 2019M10uc 0.24500300
> 7 2019M08up 0.71751360
> 8 2019M09up 0.75247310
> 9 2019M10up 0.73748790
>
> On 2020-08-17 07:46 -0500, Hadley Wickham wrote:
> | On Mon, Aug 17, 2020 at 11:23 AM Thierry Onkelinx wrote:
> | |
> | | reshape2 is a retired package. The
> | | author recommends to use his new
> | | package tidyr.
> |
> | We previously used the term retired to
> | suggest that the package is taking it
> | easy and relaxing, but isn't dead.
>
> Haha :)
>
> | This causes a lot of confusion so we
> | now call this state "superseded" —
> | we'll continue to keep reshape2 (and
> | reshape!) on CRAN
>
> Good!
>
> | but they won't receive any new
> | features, and we believe that there
> | are now better approaches to solving
> | the same problem.
>
> Is tidyr::pivot_longer this better
> solution?  It is an easier to understand
> version of the now retired and confusing
> (for me) tidyr::gather which at least
> reigned back in 2018 (was that any good
> compared to reshape?).
>
> Best,
> Rasmus
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Rasmus Liland
Dear John,

Op ma 17 aug. 2020 om 09:52 schreef Eric Berger:
| On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx wrote:
| |
| | You are looking for tidyr::pivot_longer()
|
| Alternatively, melt() from the reshape2 package.
|
| library(reshape2)
| melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
| ="direction",value.name="percentage")

Also, stack is also possible to use:

tab <- structure(list(
date = c("2019M08", "2019M09", "2019M10"),
down = c(0.01709827, 0.02094724, 0.01750911),
uc = c(0.2653882, 0.2265797, 0.245003),
up = c(0.7175136, 0.7524731, 0.7374879)),
class = "data.frame", row.names = c(NA, -3L))

out <- utils::stack(x=tab, select=-date)
colnames(out) <- c("percentage", "direction")
out$date <- tab$date
out <- out[,sort(colnames(out))]

out

yields

 date direction percentage
1 2019M08  down 0.01709827
2 2019M09  down 0.02094724
3 2019M10  down 0.01750911
4 2019M08uc 0.26538820
5 2019M09uc 0.22657970
6 2019M10uc 0.24500300
7 2019M08up 0.71751360
8 2019M09up 0.75247310
9 2019M10up 0.73748790

On 2020-08-17 07:46 -0500, Hadley Wickham wrote:
| On Mon, Aug 17, 2020 at 11:23 AM Thierry Onkelinx wrote:
| |
| | reshape2 is a retired package. The 
| | author recommends to use his new 
| | package tidyr.
| 
| We previously used the term retired to 
| suggest that the package is taking it 
| easy and relaxing, but isn't dead. 

Haha :)

| This causes a lot of confusion so we 
| now call this state "superseded" — 
| we'll continue to keep reshape2 (and 
| reshape!) on CRAN

Good!

| but they won't receive any new 
| features, and we believe that there 
| are now better approaches to solving 
| the same problem.

Is tidyr::pivot_longer this better 
solution?  It is an easier to understand 
version of the now retired and confusing 
(for me) tidyr::gather which at least 
reigned back in 2018 (was that any good 
compared to reshape?).

Best,
Rasmus


signature.asc
Description: PGP signature
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Hadley Wickham
We previously used the term retired to suggest that the package is
taking it easy and relaxing, but isn't dead. This causes a lot of
confusion so we now call this state "superseded" — we'll continue to
keep reshape2 (and reshape!) on CRAN, but they won't receive any new
features, and we believe that there are now better approaches to
solving the same problem.

Hadley

On Mon, Aug 17, 2020 at 3:58 AM Eric Berger  wrote:
>
> Thanks for this information Thierry. I was not aware.
> The author of the packages is Hadley Wickham. He writes on Github that he
> does plan to make changes necessary to keep the package available on CRAN.
>
>
>
> On Mon, Aug 17, 2020 at 11:23 AM Thierry Onkelinx 
> wrote:
>
> > Yes. However reshape2 is a retired package. The author recommends to use
> > his new package tidyr.
> >
> > ir. Thierry Onkelinx
> > Statisticus / Statistician
> >
> > Vlaamse Overheid / Government of Flanders
> > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> > FOREST
> > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> > thierry.onkel...@inbo.be
> > Havenlaan 88 bus 73, 1000 Brussel
> > www.inbo.be
> >
> >
> > ///
> > To call in the statistician after the experiment is done may be no more
> > than asking him to perform a post-mortem examination: he may be able to say
> > what the experiment died of. ~ Sir Ronald Aylmer Fisher
> > The plural of anecdote is not data. ~ Roger Brinner
> > The combination of some data and an aching desire for an answer does not
> > ensure that a reasonable answer can be extracted from a given body of data.
> > ~ John Tukey
> >
> > ///
> >
> > 
> >
> >
> > Op ma 17 aug. 2020 om 09:52 schreef Eric Berger :
> >
> >> Alternatively, melt() from the reshape2 package.
> >>
> >> library(reshape2)
> >> melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
> >> ="direction",value.name="percentage")
> >>
> >> HTH,
> >> Eric
> >>
> >>
> >> On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help <
> >> r-help@r-project.org> wrote:
> >>
> >>> You are looking for tidyr::pivot_longer()
> >>>
> >>> Best regards,
> >>>
> >>> ir. Thierry Onkelinx
> >>> Statisticus / Statistician
> >>>
> >>> Vlaamse Overheid / Government of Flanders
> >>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
> >>> AND
> >>> FOREST
> >>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> >>> thierry.onkel...@inbo.be
> >>> Havenlaan 88 bus 73, 1000 Brussel
> >>> www.inbo.be
> >>>
> >>>
> >>> ///
> >>> To call in the statistician after the experiment is done may be no more
> >>> than asking him to perform a post-mortem examination: he may be able to
> >>> say
> >>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> >>> The plural of anecdote is not data. ~ Roger Brinner
> >>> The combination of some data and an aching desire for an answer does not
> >>> ensure that a reasonable answer can be extracted from a given body of
> >>> data.
> >>> ~ John Tukey
> >>>
> >>> ///
> >>>
> >>> 
> >>>
> >>>
> >>> Op ma 17 aug. 2020 om 09:35 schreef John :
> >>>
> >>> > Is there any quick way (dplyr?) to arrange the data
> >>> >  date  down   uc   up
> >>> > 2019M08   0.01709827 0.2653882 0.7175136
> >>> > 2019M09   0.02094724 0.2265797 0.7524731
> >>> > 2019M10   0.01750911 0.2450030 0.7374879
> >>> >
> >>> > to
> >>> >  date  direction  percentage
> >>> > 2019M08   down 0.01709827
> >>> > 2019M09   down 0.02094724
> >>> > 2019M10   down 0.01750911
> >>> > 2019M08   uc 0.2653882
> >>> > 2019M09   uc 0.2265797
> >>> > 2019M10   uc 0.2450030
> >>> > 2019M08   up  0.7175136
> >>> > 2019M09   up 0.7524731
> >>> > 2019M10   up 0.7374879
> >>> >
> >>> > [[alternative HTML version deleted]]
> >>> >
> >>> > __
> >>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> > https://stat.ethz.ch/mailman/listinfo/r-help
> >>> > PLEASE do read the posting guide
> >>> > http://www.R-project.org/posting-guide.html
> >>> > and provide commented, minimal, self-contained, reproducible code.
> >>> >
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide
> >>> http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>
>
> [[alternative HTML version deleted]]
>
> 

Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Eric Berger
Thanks for this information Thierry. I was not aware.
The author of the packages is Hadley Wickham. He writes on Github that he
does plan to make changes necessary to keep the package available on CRAN.



On Mon, Aug 17, 2020 at 11:23 AM Thierry Onkelinx 
wrote:

> Yes. However reshape2 is a retired package. The author recommends to use
> his new package tidyr.
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be
>
>
> ///
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ///
>
> 
>
>
> Op ma 17 aug. 2020 om 09:52 schreef Eric Berger :
>
>> Alternatively, melt() from the reshape2 package.
>>
>> library(reshape2)
>> melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
>> ="direction",value.name="percentage")
>>
>> HTH,
>> Eric
>>
>>
>> On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help <
>> r-help@r-project.org> wrote:
>>
>>> You are looking for tidyr::pivot_longer()
>>>
>>> Best regards,
>>>
>>> ir. Thierry Onkelinx
>>> Statisticus / Statistician
>>>
>>> Vlaamse Overheid / Government of Flanders
>>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>>> AND
>>> FOREST
>>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>>> thierry.onkel...@inbo.be
>>> Havenlaan 88 bus 73, 1000 Brussel
>>> www.inbo.be
>>>
>>>
>>> ///
>>> To call in the statistician after the experiment is done may be no more
>>> than asking him to perform a post-mortem examination: he may be able to
>>> say
>>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
>>> The plural of anecdote is not data. ~ Roger Brinner
>>> The combination of some data and an aching desire for an answer does not
>>> ensure that a reasonable answer can be extracted from a given body of
>>> data.
>>> ~ John Tukey
>>>
>>> ///
>>>
>>> 
>>>
>>>
>>> Op ma 17 aug. 2020 om 09:35 schreef John :
>>>
>>> > Is there any quick way (dplyr?) to arrange the data
>>> >  date  down   uc   up
>>> > 2019M08   0.01709827 0.2653882 0.7175136
>>> > 2019M09   0.02094724 0.2265797 0.7524731
>>> > 2019M10   0.01750911 0.2450030 0.7374879
>>> >
>>> > to
>>> >  date  direction  percentage
>>> > 2019M08   down 0.01709827
>>> > 2019M09   down 0.02094724
>>> > 2019M10   down 0.01750911
>>> > 2019M08   uc 0.2653882
>>> > 2019M09   uc 0.2265797
>>> > 2019M10   uc 0.2450030
>>> > 2019M08   up  0.7175136
>>> > 2019M09   up 0.7524731
>>> > 2019M10   up 0.7374879
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> > http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>> >
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread John
Thanks!

Thierry Onkelinx  於 2020年8月17日 週一 下午4:23寫道:

> Yes. However reshape2 is a retired package. The author recommends to use
> his new package tidyr.
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be
>
>
> ///
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ///
>
> 
>
>
> Op ma 17 aug. 2020 om 09:52 schreef Eric Berger :
>
>> Alternatively, melt() from the reshape2 package.
>>
>> library(reshape2)
>> melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
>> ="direction",value.name="percentage")
>>
>> HTH,
>> Eric
>>
>>
>> On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help <
>> r-help@r-project.org> wrote:
>>
>>> You are looking for tidyr::pivot_longer()
>>>
>>> Best regards,
>>>
>>> ir. Thierry Onkelinx
>>> Statisticus / Statistician
>>>
>>> Vlaamse Overheid / Government of Flanders
>>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>>> AND
>>> FOREST
>>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>>> thierry.onkel...@inbo.be
>>> Havenlaan 88 bus 73, 1000 Brussel
>>> www.inbo.be
>>>
>>>
>>> ///
>>> To call in the statistician after the experiment is done may be no more
>>> than asking him to perform a post-mortem examination: he may be able to
>>> say
>>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
>>> The plural of anecdote is not data. ~ Roger Brinner
>>> The combination of some data and an aching desire for an answer does not
>>> ensure that a reasonable answer can be extracted from a given body of
>>> data.
>>> ~ John Tukey
>>>
>>> ///
>>>
>>> 
>>>
>>>
>>> Op ma 17 aug. 2020 om 09:35 schreef John :
>>>
>>> > Is there any quick way (dplyr?) to arrange the data
>>> >  date  down   uc   up
>>> > 2019M08   0.01709827 0.2653882 0.7175136
>>> > 2019M09   0.02094724 0.2265797 0.7524731
>>> > 2019M10   0.01750911 0.2450030 0.7374879
>>> >
>>> > to
>>> >  date  direction  percentage
>>> > 2019M08   down 0.01709827
>>> > 2019M09   down 0.02094724
>>> > 2019M10   down 0.01750911
>>> > 2019M08   uc 0.2653882
>>> > 2019M09   uc 0.2265797
>>> > 2019M10   uc 0.2450030
>>> > 2019M08   up  0.7175136
>>> > 2019M09   up 0.7524731
>>> > 2019M10   up 0.7374879
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> > http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>> >
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Thierry Onkelinx via R-help
Yes. However reshape2 is a retired package. The author recommends to use
his new package tidyr.

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///




Op ma 17 aug. 2020 om 09:52 schreef Eric Berger :

> Alternatively, melt() from the reshape2 package.
>
> library(reshape2)
> melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
> ="direction",value.name="percentage")
>
> HTH,
> Eric
>
>
> On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help <
> r-help@r-project.org> wrote:
>
>> You are looking for tidyr::pivot_longer()
>>
>> Best regards,
>>
>> ir. Thierry Onkelinx
>> Statisticus / Statistician
>>
>> Vlaamse Overheid / Government of Flanders
>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
>> FOREST
>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>> thierry.onkel...@inbo.be
>> Havenlaan 88 bus 73, 1000 Brussel
>> www.inbo.be
>>
>>
>> ///
>> To call in the statistician after the experiment is done may be no more
>> than asking him to perform a post-mortem examination: he may be able to
>> say
>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
>> The plural of anecdote is not data. ~ Roger Brinner
>> The combination of some data and an aching desire for an answer does not
>> ensure that a reasonable answer can be extracted from a given body of
>> data.
>> ~ John Tukey
>>
>> ///
>>
>> 
>>
>>
>> Op ma 17 aug. 2020 om 09:35 schreef John :
>>
>> > Is there any quick way (dplyr?) to arrange the data
>> >  date  down   uc   up
>> > 2019M08   0.01709827 0.2653882 0.7175136
>> > 2019M09   0.02094724 0.2265797 0.7524731
>> > 2019M10   0.01750911 0.2450030 0.7374879
>> >
>> > to
>> >  date  direction  percentage
>> > 2019M08   down 0.01709827
>> > 2019M09   down 0.02094724
>> > 2019M10   down 0.01750911
>> > 2019M08   uc 0.2653882
>> > 2019M09   uc 0.2265797
>> > 2019M10   uc 0.2450030
>> > 2019M08   up  0.7175136
>> > 2019M09   up 0.7524731
>> > 2019M10   up 0.7374879
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Eric Berger
Alternatively, melt() from the reshape2 package.

library(reshape2)
melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name
="direction",value.name="percentage")

HTH,
Eric


On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help <
r-help@r-project.org> wrote:

> You are looking for tidyr::pivot_longer()
>
> Best regards,
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be
>
>
> ///
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ///
>
> 
>
>
> Op ma 17 aug. 2020 om 09:35 schreef John :
>
> > Is there any quick way (dplyr?) to arrange the data
> >  date  down   uc   up
> > 2019M08   0.01709827 0.2653882 0.7175136
> > 2019M09   0.02094724 0.2265797 0.7524731
> > 2019M10   0.01750911 0.2450030 0.7374879
> >
> > to
> >  date  direction  percentage
> > 2019M08   down 0.01709827
> > 2019M09   down 0.02094724
> > 2019M10   down 0.01750911
> > 2019M08   uc 0.2653882
> > 2019M09   uc 0.2265797
> > 2019M10   uc 0.2450030
> > 2019M08   up  0.7175136
> > 2019M09   up 0.7524731
> > 2019M10   up 0.7374879
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Thierry Onkelinx via R-help
You are looking for tidyr::pivot_longer()

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///




Op ma 17 aug. 2020 om 09:35 schreef John :

> Is there any quick way (dplyr?) to arrange the data
>  date  down   uc   up
> 2019M08   0.01709827 0.2653882 0.7175136
> 2019M09   0.02094724 0.2265797 0.7524731
> 2019M10   0.01750911 0.2450030 0.7374879
>
> to
>  date  direction  percentage
> 2019M08   down 0.01709827
> 2019M09   down 0.02094724
> 2019M10   down 0.01750911
> 2019M08   uc 0.2653882
> 2019M09   uc 0.2265797
> 2019M10   uc 0.2450030
> 2019M08   up  0.7175136
> 2019M09   up 0.7524731
> 2019M10   up 0.7374879
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread John
Is there any quick way (dplyr?) to arrange the data
 date  down   uc   up
2019M08   0.01709827 0.2653882 0.7175136
2019M09   0.02094724 0.2265797 0.7524731
2019M10   0.01750911 0.2450030 0.7374879

to
 date  direction  percentage
2019M08   down 0.01709827
2019M09   down 0.02094724
2019M10   down 0.01750911
2019M08   uc 0.2653882
2019M09   uc 0.2265797
2019M10   uc 0.2450030
2019M08   up  0.7175136
2019M09   up 0.7524731
2019M10   up 0.7374879

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.