Re: [R] Dplyr question

2022-06-23 Thread PIKAL Petr
Hallo all

Various suggestion were made but with this simple task I immediatelly
thought about reshape2 melt function.

x <- "Time_stampP1A0B0D P190-90D
'Jun-10 10:34'  -0.000208   -0.000195
'Jun-10 10:51'  -0.000228   -0.000188
'Jun-10 11:02'  -0.000234   -0.000204
'Jun-10 11:17'  -0.00022-0.000205
'Jun-10 11:25'  -0.000238   -0.000195"
df1 <- read.table(textConnection(x), header = TRUE, check.names = FALSE)

library(reshape2)
melt(df1)
Using Time_stamp as id variables
 Time_stamp variable value
1  Jun-10 10:34  P1A0B0D -0.000208
2  Jun-10 10:51  P1A0B0D -0.000228
3  Jun-10 11:02  P1A0B0D -0.000234
4  Jun-10 11:17  P1A0B0D -0.000220
5  Jun-10 11:25  P1A0B0D -0.000238
6  Jun-10 10:34 P190-90D -0.000195
7  Jun-10 10:51 P190-90D -0.000188
8  Jun-10 11:02 P190-90D -0.000204
9  Jun-10 11:17 P190-90D -0.000205
10 Jun-10 11:25 P190-90D -0.000195

You need only rename columns if necessary.
Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Richard O'Keefe
> Sent: Thursday, June 23, 2022 2:29 AM
> To: Thomas Subia 
> Cc: r-help@r-project.org
> Subject: Re: [R] Dplyr question
> 
> Why do you want to use dplyr?
> It's easy using base R.
> 
> original <- ...
> a <- cbind(original[,-3], Location=colnames(original)[2]) colnames(a)[2]
<-
> "Measurement"
> b <- cbind(original[,-2], Location=colnames(original)[3]) colnames(b)[2]
<-
> "Measurement"
> result <- rbind(a, b)[,c(1,3,2)]
> 
> 
> 
> 
> On Wed, 22 Jun 2022 at 04:23, Thomas Subia
> 
> wrote:
> 
> > Colleagues:
> >
> > The header of my data set is:
> > Time_stamp  P1A0B0D P190-90D
> > Jun-10 10:34-0.000208   -0.000195
> > Jun-10 10:51-0.000228   -0.000188
> > Jun-10 11:02-0.000234   -0.000204
> > Jun-10 11:17-0.00022-0.000205
> > Jun-10 11:25-0.000238   -0.000195
> >
> > I want my data set to resemble:
> >
> > Time_stamp  LocationMeasurement
> > Jun-10 10:34P1A0B0D -0.000208
> > Jun-10 10:51P1A0B0D -0.000228
> > Jun-10 11:02P1A0B0D -0.000234
> > Jun-10 11:17P1A0B0D -0.00022
> > Jun-10 11:25P1A0B0D -0.000238
> > Jun-10 10:34P190-90D-0.000195
> > Jun-10 10:51P190-90D-0.000188
> > Jun-10 11:02P190-90D-0.000204
> > Jun-10 11:17P190-90D-0.000205
> > Jun-10 11:25P190-90D-0.000195
> >
> > I need some advice on how to do this using dplyr.
> >
> > V/R
> > Thomas Subia
> >
> > FM Industries, Inc. - NGK Electronics, USA | www.fmindustries.com
> > 221 Warren Ave, Fremont, CA 94539
> >
> > "En Dieu nous avons confiance, tous les autres doivent apporter des
> > donnees"
> >
> > __
> > 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-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] Dplyr question

2022-06-21 Thread Jeff Newmiller
dplyr != tidyverse.

And questions that presuppose a solution method demonstrate closed-mindedness, 
and reduce the chance that novel solutions will be put forth, or that the 
questioner will actually learn something instead of using the list as a 
glorified search engine.

It is not that answers should avoid contributed packages, but questioners 
should be open to all answers. This is not the tidyverse help list, it is the 
R-help list, and telling people to stay quiet if they cannot conform to the 
biases of the questioner is self-defeating, since the point of the list is to 
learn how problems can be solved. An open mind can learn for instance that 
searching for functions that reshape dataframes in dplyr is doomed and that 
those functions are found elsewhere can use that info to successfully form 
Google queries later without coming back to the list later for the same 
question.

FWIW I use certain tidyverse packages frequently. But solutions using them are 
not always as useful for learning opportunities as base R solutions are.

Oh, and pipes are orthogonal to reshaping... searching for magrittr and 
reshaping isn't a productive association for searches.

On June 21, 2022 4:13:50 PM PDT, Avi Gross via R-help  
wrote:
>Bert and Others,
>
>Now that newer versions of R support a reasonable pipeline method, I think 
>there may be more interest in using functions designed to be easy to use in 
>pipelines, including wrappers that just re-arrange the order for existing 
>functions to make the first argument the one passed along the pipeline.
>
>When people say "dplyr' now it is indeed a specific package but  some use it 
>to mean more like the "tidyverse" group of packages that are meant to operate 
>well together and they includes the "tidyr" package.
>
>The intuitively OBVIOUS solution using base R that is shown is actually a bit 
>restricted and does not trivially scale up to deal with lots more columns that 
>are to be consolidated, perhaps in multiple batches and based on things like 
>suffixes in the names and so on that the tidyverse functions are able to 
>handle. And if it matters, you may want to keep the order of the rows 
>relatively intact and the solution offered does not.
>
>But packages like dplyr are not a full solution and most people would be 
>better off learning all about what core R offers and only supplementing it 
>here and there with selected packages. If you ever have to read code others 
>wrote or modified, ...
>
>In any case, THIS forum seems dedicated for a purpose that precludes more than 
>an aside about packages. Very little that is in packages cannot in theory be 
>done using mostly regular R but I am not sure if that is any longer true or 
>wise. Many packages re-write R functionality as something like much faster 
>code in C or C++ or make use of some R code that is more efficient than you 
>might cobble together on your own. Some is also very general and allows 
>programming at higher levels of abstraction and I specifically include the 
>pipeline methods (now also in R) as such a level of abstraction.
>The topic, loosely, was how to transform your data.frame (or equivalent) from 
>what some call WIDE form to LONG form. That is often done in pipelines where 
>after some steps, the resulting data has to be transformed before being given 
>to a program like one doing graphics with ggplot() and no amount of lecturing 
>suggesting we use native R graphics for everything will in the slightest bit 
>convince me.
>
>So the supplied method, unless suitably placed in a function that takes a 
>data.frame as a first argument and returns the modified new one as a result, 
>will only help for some purposes and be a pain for others as you pause and 
>leave any pipeline to make the change and then ...
>
>As was said, intuitive is fairly meaningless as my personal intuition often 
>intuits multiple ways of looking at something, each one being its own 
>intuitive way and the task often is simply to pick one based on additional 
>factors. It may be intuitively obvious to do it the shortest and easiest way 
>imaginable but also obvious if you will need this again, to make it properly 
>commented and documented and even at times do more error checking or do more 
>general tasks ...
>At MY stage I think I know enough but also see no reason to waste lots of time 
>doing things in many steps with lots of possible mistakes on my part when a 
>few well-coordinated and tested packages make it easy.
>To each their own. But I am NOT suggesting this forum should change, there are 
>others that can accommodate people. And there are way more packages out there 
>that most of us are not even aware of exist!
>
>
>-Original Message-
>From: Bert Gunter 
>To: Rui Barradas 
>Cc: r-hel

Re: [R] Dplyr question

2022-06-21 Thread Rui Barradas

Hello,

Right, intuitive is (very) relative. I was thinking of base function 
stats::reshape. Its main difficulty is, imho, to reshape to both wide 
and long formats. Compared to it, tidyr::pivot_* are (much?) easier to 
understand.


Here is a stats::reshape solution.


df_long <- reshape(
  data = df1,
  idvar = "Time_stamp",
  varying = list(2:3),
  v.names = "Measurement",
  direction = "long")

df_long$time <- sort(names(df1)[-1])[df_long$time]
names(df_long)[2] <- "Location"
df_long
#>  Time_stamp Location Measurement
#> Jun-10 10:34.1 Jun-10 10:34 P190-90D   -0.000208
#> Jun-10 10:51.1 Jun-10 10:51 P190-90D   -0.000228
#> Jun-10 11:02.1 Jun-10 11:02 P190-90D   -0.000234
#> Jun-10 11:17.1 Jun-10 11:17 P190-90D   -0.000220
#> Jun-10 11:25.1 Jun-10 11:25 P190-90D   -0.000238
#> Jun-10 10:34.2 Jun-10 10:34  P1A0B0D   -0.000195
#> Jun-10 10:51.2 Jun-10 10:51  P1A0B0D   -0.000188
#> Jun-10 11:02.2 Jun-10 11:02  P1A0B0D   -0.000204
#> Jun-10 11:17.2 Jun-10 11:17  P1A0B0D   -0.000205
#> Jun-10 11:25.2 Jun-10 11:25  P1A0B0D   -0.000195


Hope this helps,

Rui Barradas

Às 19:25 de 21/06/2022, Bert Gunter escreveu:

Heh heh. Well "intuitiveness" is in the mind of the intuiter. ;-)
One might even say that Jeff's and John's solutions were the most 
"intuitive" as they involved nothing more than the "straightforward" 
application of standard base R functionality. (Do note the scare quotes 
around 'straightforward'.) Of course, other factors may well be 
decisive, such as efficiency, generalizability to the *real* problem and 
data, and so forth.


Best to all,
Bert

On Tue, Jun 21, 2022 at 10:50 AM Rui Barradas > wrote:


Hello,

pivot_longer is a package tidyr function, not dplyr. I find its syntax
very intuitive. Here is a solution.



x <- "Time_stamp    P1A0B0D P190-90D
'Jun-10 10:34'  -0.000208   -0.000195
'Jun-10 10:51'  -0.000228   -0.000188
'Jun-10 11:02'  -0.000234   -0.000204
'Jun-10 11:17'  -0.00022    -0.000205
'Jun-10 11:25'  -0.000238   -0.000195"
df1 <- read.table(textConnection(x), header = TRUE, check.names = FALSE)

suppressPackageStartupMessages({
    library(dplyr)
    library(tidyr)
})

df1 %>%
    pivot_longer(
      cols = -Time_stamp,     # or starts_with("P1")
      names_to = "Location",
      values_to = "Measurement"
    ) %>%
    arrange(desc(Location), Time_stamp)
#> # A tibble: 10 × 3
#>    Time_stamp   Location Measurement
#>                      
#>  1 Jun-10 10:34 P1A0B0D    -0.000208
#>  2 Jun-10 10:51 P1A0B0D    -0.000228
#>  3 Jun-10 11:02 P1A0B0D    -0.000234
#>  4 Jun-10 11:17 P1A0B0D    -0.00022
#>  5 Jun-10 11:25 P1A0B0D    -0.000238
#>  6 Jun-10 10:34 P190-90D   -0.000195
#>  7 Jun-10 10:51 P190-90D   -0.000188
#>  8 Jun-10 11:02 P190-90D   -0.000204
#>  9 Jun-10 11:17 P190-90D   -0.000205
#> 10 Jun-10 11:25 P190-90D   -0.000195



Hope this helps,

Rui Barradas

Às 17:22 de 21/06/2022, Thomas Subia escreveu:
 > Colleagues:
 >
 > The header of my data set is:
 > Time_stamp    P1A0B0D P190-90D
 > Jun-10 10:34  -0.000208       -0.000195
 > Jun-10 10:51  -0.000228       -0.000188
 > Jun-10 11:02  -0.000234       -0.000204
 > Jun-10 11:17  -0.00022        -0.000205
 > Jun-10 11:25  -0.000238       -0.000195
 >
 > I want my data set to resemble:
 >
 > Time_stamp    Location        Measurement
 > Jun-10 10:34  P1A0B0D -0.000208
 > Jun-10 10:51  P1A0B0D -0.000228
 > Jun-10 11:02  P1A0B0D -0.000234
 > Jun-10 11:17  P1A0B0D -0.00022
 > Jun-10 11:25  P1A0B0D -0.000238
 > Jun-10 10:34  P190-90D        -0.000195
 > Jun-10 10:51  P190-90D        -0.000188
 > Jun-10 11:02  P190-90D        -0.000204
 > Jun-10 11:17  P190-90D        -0.000205
 > Jun-10 11:25  P190-90D        -0.000195
 >
 > I need some advice on how to do this using dplyr.
 >
 > V/R
 > Thomas Subia
 >
 > FM Industries, Inc. - NGK Electronics, USA | www.fmindustries.com

 > 221 Warren Ave, Fremont, CA 94539
 >
 > "En Dieu nous avons confiance, tous les autres doivent apporter
des donnees"
 >
 > __
 > 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-help@r-project.org  mailing list --
To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
 

Re: [R] Dplyr question

2022-06-21 Thread Jeff Newmiller
Beware of being too specific about how you want something solved... not just 
here, but in all contexts. Your question is like "how do I slice this apple 
with this potholder"... dplyr actually doesn't do that, and you can benefit 
from learning how to do things in general, not just in your preferred idiom.

ans <- 
do.call( rbind
   , lapply( names(dta[ -1 ])
   , function( nm )
   data.frame( dta[1]
 , Location = nm
 , Measurement = dta[[nm]]
 , stringsAsFactors = FALSE ) ) )

On June 21, 2022 9:22:48 AM PDT, Thomas Subia  
wrote:
>Colleagues:
>
>The header of my data set is:
>Time_stamp P1A0B0D P190-90D
>Jun-10 10:34   -0.000208   -0.000195
>Jun-10 10:51   -0.000228   -0.000188
>Jun-10 11:02   -0.000234   -0.000204
>Jun-10 11:17   -0.00022-0.000205
>Jun-10 11:25   -0.000238   -0.000195
>
>I want my data set to resemble:
>
>Time_stamp LocationMeasurement
>Jun-10 10:34   P1A0B0D -0.000208
>Jun-10 10:51   P1A0B0D -0.000228
>Jun-10 11:02   P1A0B0D -0.000234
>Jun-10 11:17   P1A0B0D -0.00022
>Jun-10 11:25   P1A0B0D -0.000238
>Jun-10 10:34   P190-90D-0.000195
>Jun-10 10:51   P190-90D-0.000188
>Jun-10 11:02   P190-90D-0.000204
>Jun-10 11:17   P190-90D-0.000205
>Jun-10 11:25   P190-90D-0.000195
>
>I need some advice on how to do this using dplyr.
>
>V/R
>Thomas Subia
>
>FM Industries, Inc. - NGK Electronics, USA | www.fmindustries.com 
>221 Warren Ave, Fremont, CA 94539 
>
>"En Dieu nous avons confiance, tous les autres doivent apporter des donnees"
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Dplyr question

2022-06-21 Thread Ebert,Timothy Aaron
I do not see how to do this with exclusively dplyr commands. I might be able to 
make it work by including commands outside of dplyr, but at that point I would 
use pivot_longer() from the tidyr package.

Tim

-Original Message-
From: R-help  On Behalf Of Thomas Subia
Sent: Tuesday, June 21, 2022 12:23 PM
To: r-help@r-project.org
Subject: [R] Dplyr question

[External Email]

Colleagues:

The header of my data set is:
Time_stamp  P1A0B0D P190-90D
Jun-10 10:34-0.000208   -0.000195
Jun-10 10:51-0.000228   -0.000188
Jun-10 11:02-0.000234   -0.000204
Jun-10 11:17-0.00022-0.000205
Jun-10 11:25-0.000238   -0.000195

I want my data set to resemble:

Time_stamp  LocationMeasurement
Jun-10 10:34P1A0B0D -0.000208
Jun-10 10:51P1A0B0D -0.000228
Jun-10 11:02P1A0B0D -0.000234
Jun-10 11:17P1A0B0D -0.00022
Jun-10 11:25P1A0B0D -0.000238
Jun-10 10:34P190-90D-0.000195
Jun-10 10:51P190-90D-0.000188
Jun-10 11:02P190-90D-0.000204
Jun-10 11:17P190-90D-0.000205
Jun-10 11:25P190-90D-0.000195

I need some advice on how to do this using dplyr.

V/R
Thomas Subia

FM Industries, Inc. - NGK Electronics, USA | 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.fmindustries.com=DwIFAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=2wtqsRoT5-Y52Nm7oSjNuHNQHkSq2Eau1NqsSFofmKxuHYYVfjvnWxMdz4-ihkH_=wC7lz5W60gl0hAYdOMsXi6BiQ7LmX1r-vSkIHY_78IY=
221 Warren Ave, Fremont, CA 94539

"En Dieu nous avons confiance, tous les autres doivent apporter des donnees"

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwIFAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=2wtqsRoT5-Y52Nm7oSjNuHNQHkSq2Eau1NqsSFofmKxuHYYVfjvnWxMdz4-ihkH_=Xb1jmlqPlfkqfb6U6vZjMhHn0dWhTZ_Tj-k4ZHpGXFY=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwIFAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=2wtqsRoT5-Y52Nm7oSjNuHNQHkSq2Eau1NqsSFofmKxuHYYVfjvnWxMdz4-ihkH_=D8A_JX8FXGErCjS4rD4k9S200L_F33HHrt0jIKJdRGM=
and provide commented, minimal, self-contained, reproducible code.

__
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] Dplyr question

2020-10-15 Thread Dr Eberhard W Lisse
This is well described in the manual.

Sounds like homework...

el

On 15/10/2020 12:39, Nico Gutierrez wrote:
> Hi All,
> 
> Trying to get familiar with dplyr so I have a basic question:
> 
> How to summarise sum(Values) per species, maintaining Code column (each 
> species has a Code):
> 
>   Species Values   Code
> 1Acanthocybium solandri33 LC
> 2Makaira nigricans20  VU
> 3Makaira nigricans 20 VU
> 4.   Makaira nigricans 20 VU
> 5   Sarda sarda2  LC
> 4Lethrinus lentjan   12   LC
> 5Raja pita8   DD
> 6Raja pita2   DD
> 
> I need:
> 
>  Species  Values   Code
> 1Acanthocybium solandri33 LC
> 2Makaira nigricans60  VU
> 3   Sarda sarda2  LC
> 4Lethrinus lentjan   12   LC
> 5Raja pita10  DD
> 
> 
> Thanks :)
> __
> 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.
> 

-- 
Dr. Eberhard W. Lisse   \ /   Obstetrician & Gynaecologist 
e...@lisse.na / *  |  Telephone: +264 81 124 6733 (cell)
PO Box 8421 Bachbrecht  \  /  If this email is signed with GPG/PGP
10007, Namibia   ;/ Sect 20 of Act No. 4 of 2019 may apply

__
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] Dplyr question

2020-10-15 Thread Nico Gutierrez
Hi All,

Trying to get familiar with dplyr so I have a basic question:

How to summarise sum(Values) per species, maintaining Code column (each species 
has a Code):

  Species   Values   Code
1Acanthocybium solandri33   LC
2Makaira nigricans  20  VU
3Makaira nigricans 20   VU
4.   Makaira nigricans 20   VU
5 Sarda sarda2  LC
4Lethrinus lentjan   12 LC
5Raja pita  8   DD
6Raja pita  2   DD

I need:

 SpeciesValues   Code
1Acanthocybium solandri33   LC
2Makaira nigricans  60  VU
3 Sarda sarda2  LC
4Lethrinus lentjan   12 LC
5Raja pita  10  DD


Thanks :)
__
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] dplyr question

2015-09-07 Thread PIKAL Petr
Hi

Why do you post the same question without following Sarah's advice?

You can clearly see that due your HTML posting your data are terrible mess and 
we do not have slightest idea what you really want.

So again. Please copy to next mail result of

dput(head(df, 20))

and explain what shall be the result.

And change your mail client to post in plain text.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ragia
> Ibrahim
> Sent: Sunday, September 06, 2015 7:41 PM
> To: r-help@r-project.org
> Subject: [R] dplyr question
>
> Dear group,
> I have the following data frame df
>
>Measure_id i j id value1   1 5 1  1   2.02   1 5 2
> 1   2.03   1 5 1  2   1.54   1 5 2  2   1.55
> 1 5 1  3   0.06   1 5 2  3   0.07   1 5 1  4   0.08
> 1 5 2  4   1.09   1 5 1  5   1.010  1 5 2  5   2.0..
> ... . . ..   ...I want to add a probability column,  the prob column
> depends on id grouped by for each ithe rank will be current (value /
> max value ) for the same id for specific i, it would be
>  Measure_id i j id valueprob1   1 5 1  1   2.0  2/2
> 2   1 5 2  1   2.0  2/2  3   1 5 1  2   1.5
> 1.5/1.5   4   1 5 2  2   1.5  1.5/1.5 5   1 5 1
> 3   0.0  06   1 5 2  3   0.0  07   1 5
> 1  4   0.0  0/1  8   1 5 2  4   1.0  1/1  9
> 1 5 1  5   1.0  1/210  1 5 2  5   2.0  2/3..
> ... . . ..   ...
> then I want to add a rank coulmn that rank regarding probability, if
> the probability equal they took the same rank for thesame id belongs to
> the same i, otherwize lower probability took higher rank for examole if
> we have three values for i=7 and for the three values the id is 1 and
> the probability is ( .2,.4,.5) the rank should be 3,2,1
> replying  highly appreciatedRagia
>   [[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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs th

[R] dplyr question

2015-09-06 Thread Ragia Ibrahim
Dear group,
I have the following data frame df
 
   Measure_id i j id value1   1 5 1  1   2.02   1 5 2  1   2.03 
  1 5 1  2   1.54   1 5 2  2   1.55   1 5 1  3   0.06   
1 5 2  3   0.07   1 5 1  4   0.08   1 5 2  4   1.09 
  1 5 1  5   1.010  1 5 2  5   2.0..... . . ..   ...I want 
to add a probability column,  the prob column depends on id grouped by for each 
ithe rank will be current (value / max value ) for the same id for specific i, 
it would be
 Measure_id i j id valueprob1   1 5 1  1   2.0  2/2  2  
 1 5 2  1   2.0  2/2  3   1 5 1  2   1.5  1.5/1.5   
4   1 5 2  2   1.5  1.5/1.5 5   1 5 1  3   0.0  
06   1 5 2  3   0.0  07   1 5 1  4   0.0  0/1  
8   1 5 2  4   1.0  1/1  9   1 5 1  5   1.0  
1/210  1 5 2  5   2.0  2/3..... . . ..   ...
then I want to add a rank coulmn that rank regarding probability, if the 
probability equal they took the same rank for thesame id belongs to the same i, 
otherwize lower probability took higher rank for examole if we have three 
values for i=7 and for the three values the id is 1 and the probability is ( 
.2,.4,.5) the rank should be 3,2,1
replying  highly appreciatedRagia 
[[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.