Displaying 17 results from an estimated 17 matches for "if_else".
2018 Feb 21
7
alternative for multiple if_else statements
Hi, I am having trouble trying to figure out why if_else is behaving the way it is, it may be my code or the way the data is structured.
Below is a snapshot of a database am working on and it represents a longitudinal survey of study participants in a trial with weekly follow up.
The variable "survey_start" represents the start of the study-d...
2018 Feb 22
0
alternative for multiple if_else statements
...ot;2015-04-01",
"2016-03-01",
"2017-01-01")))
might work.
Best,
Ista
On Wed, Feb 21, 2018 at 3:33 PM, Kevin Wamae <KWamae at kemri-wellcome.org> wrote:
> Hi, I am having trouble trying to figure out why if_else is behaving the way it is, it may be my code or the way the data is structured.
>
> Below is a snapshot of a database am working on and it represents a longitudinal survey of study participants in a trial with weekly follow up.
>
> The variable "survey_start" represents the st...
2018 Feb 26
0
alternative for multiple if_else statements
...", ave(year, studyno, FUN=min), sep="_")
S Ellison
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Kevin
> Wamae
> Sent: 21 February 2018 20:34
> To: R-help at r-project.org
> Subject: [R] alternative for multiple if_else statements
>
> Hi, I am having trouble trying to figure out why if_else is behaving the way it is,
> it may be my code or the way the data is structured.
>
> Below is a snapshot of a database am working on and it represents a
> longitudinal survey of study participants in a tria...
2018 Feb 22
0
alternative for multiple if_else statements
...>
> *From: *Eric Berger <ericjberger at gmail.com>
> *Date: *Thursday, 22 February 2018 at 13:05
> *To: *Kevin Wamae <KWamae at kemri-wellcome.org>
> *Cc: *"R-help at r-project.org" <R-help at r-project.org>
> *Subject: *Re: [R] alternative for multiple if_else statements
>
>
>
> Hi,
>
> 1. I think the reason that the different ordering leads to different
> results is because of the following:
>
> date[ some condition is true ][1]
>
> will give you an NA if there are no rows where 'some condition holds'.
&g...
2016 Aug 12
2
ifelse() woes ... can we agree on a ifelse2() ?
...> necessary).
Yes, you are right, that's a good point:
if we don't want to "take everything" from 'test' (which is
symmetric in 'yes' and 'no'), but rather from 'yes' and 'no', we
either must be "very strict" -- as e.g., dplyr::if_else() -- or
then have (border) cases where the first argument takes
precedence over the second as in other cases in R
e.g. how names/dimnames of the result are determined in cbind(),
rbind(), and I think data.frame().
>> One possibility would also be to consider a "numbers-only"...
2016 Aug 15
2
ifelse() woes ... can we agree on a ifelse2() ?
...consider a "numbers-only" or
>> >> rather "same type"-only {e.g., would also work for characters}
>> >> version.
>>
>> > I don't know what you mean by these.
>>
>> In the mean time, Bob Rudis mentioned dplyr::if_else(),
>> which is very relevant, thank you Bob!
>>
>> As I have found, that actually works in such a "same type"-only way:
>> It does not try to coerce, but gives an error when the classes
>> differ, even in this somewhat debatable case :
>>
>> &g...
2016 Aug 12
0
ifelse() woes ... can we agree on a ifelse2() ?
...ibility would also be to consider a "numbers-only" or
> >> rather "same type"-only {e.g., would also work for characters}
> >> version.
>
> > I don't know what you mean by these.
>
> In the mean time, Bob Rudis mentioned dplyr::if_else(),
> which is very relevant, thank you Bob!
>
> As I have found, that actually works in such a "same type"-only way:
> It does not try to coerce, but gives an error when the classes
> differ, even in this somewhat debatable case :
>
> > dplyr::if_else(c(TRUE, FA...
2016 Nov 15
2
ifelse() woes ... can we agree on a ifelse2() ?
...gt;> rather "same type"-only {e.g.,
> >>> would also work for characters} >> version.
> >>>
> >>> > I don't know what you mean by these.
> >>>
> >>> In the mean time, Bob Rudis mentioned dplyr::if_else(),
> >>> which is very relevant, thank you Bob!
> >>>
> >>> As I have found, that actually works in such a "same
> >>> type"-only way: It does not try to coerce, but gives an
> >>> error when the classes diffe...
2016 Nov 15
0
ifelse() woes ... can we agree on a ifelse2() ?
...t;numbers-only" or >> rather "same type"-only {e.g.,
>>> would also work for characters} >> version.
>>>
>>> > I don't know what you mean by these.
>>>
>>> In the mean time, Bob Rudis mentioned dplyr::if_else(),
>>> which is very relevant, thank you Bob!
>>>
>>> As I have found, that actually works in such a "same
>>> type"-only way: It does not try to coerce, but gives an
>>> error when the classes differ, even in this somewhat...
2016 Nov 22
0
ifelse() woes ... can we agree on a ifelse2() ?
...ut I wonder what exactly you
> mean when you want recycling behavior.
Thank you, Gabe.
Note that my premise was really to get *away* from inheriting
too much from 'test'.
Hence, I have *not* been talking about replacing ifelse() but
rather of providing a new ifelse2()
[ or if_else() if Hadley was willing to ditch the dplyr one
in favor of a base one]
> Specifically, based on an unrelated discussion with Henrik Bengtsson on
> Twitter, I wonder if preserving the recycling behavior test is longer than
> yes, no, but making the case where...
2016 Nov 26
3
ifelse() woes ... can we agree on a ifelse2() ?
...matches the length of the result, it chooses recycled (or truncated) 'yes'.
It uses 'rep' on the index and subsetting as a substitute for 'rep' on the value.
It requires 'length' method that is compatible with subsetting.
Additionally, it uses the same idea as dplyr::if_else, or more precisely the helper function 'replace_with'. It doesn't use 'rep' if the length of 'no' is 1 or is the same as the length of the result. For subassignment with value of length 1, recycling happens by itself and NA in index is OK.
It limits 'NA.' to be o...
2018 Feb 12
4
problema de fechas
hola Patricio, usa:
dplyr::if_else
[[alternative HTML version deleted]]
2016 Nov 28
0
ifelse() woes ... can we agree on a ifelse2() ?
...esult, it chooses recycled (or truncated) 'yes'.
> It uses 'rep' on the index and subsetting as a substitute for 'rep' on the value.
> It requires 'length' method that is compatible with subsetting.
> Additionally, it uses the same idea as dplyr::if_else, or more precisely the helper function 'replace_with'. It doesn't use 'rep' if the length of 'no' is 1 or is the same as the length of the result. For subassignment with value of length 1, recycling happens by itself and NA in index is OK.
> It limits 'NA.'...
2017 Sep 08
0
need help for finding related sales with R
...nager) %>%
mutate("total_sales_of_a_manager" = sum(Clients_cost),
"Accumulated_sales" = cumsum(`Clients_cost`),
"Accumulated_sales_share" =
Accumulated_sales/total_sales_of_a_manager)
%>%
ungroup() %>%
mutate("managers_ABC = if_else(Accumulated_sales_share < 0.8, "A",
if_else(Accumulated_sales_share <
0.95, "B","C")))
So, here we come to the main problem: i need to add 3 more columnes with
the SKU statuses:
if the the SKU is in top 20% of clients...
2016 Aug 06
4
ifelse() woes ... can we agree on a ifelse2() ?
Dear R-devel readers,
( = people interested in the improvement and development of R).
This is not the first time that this topic is raised.
and I am in now state to promise that anything will result from
this thread ...
Still, I think the majority among us has agreed that
1) you should never use ifelse(test, yes, no)
if you know that length(test) == 1, in which case
if(test) yes
2023 Jan 27
0
Resumen de R-help-es, Vol 167, Envío 10
...unique()
> + res_df <- data.table()
> + for (i in 1:length(nam_val)) {
> + cols_tmp <- nam_val[i]
> + df_tmp <- df %>% select.(starts_with(cols_tmp)) %>%
> + rename.( a = 1) %>%
> + rename.( b = 2) %>%
> + mutate.( c = if_else.( a == 1 | b == 1, 1, 0)) %>%
> + select.(c) %>%
> + as.data.table()
> + names(df_tmp) <- paste0(cols_tmp, "c")
> + res_df <- cbind(res_df, df_tmp)
> + }
> + return(res_df)
> + }
> >
> > #--- Sobre df creado
&g...
2023 Jan 28
0
Resumen de R-help-es, Vol 167, Envío 10
...unique()
> + res_df <- data.table()
> + for (i in 1:length(nam_val)) {
> + cols_tmp <- nam_val[i]
> + df_tmp <- df %>% select.(starts_with(cols_tmp)) %>%
> + rename.( a = 1) %>%
> + rename.( b = 2) %>%
> + mutate.( c = if_else.( a == 1 | b == 1, 1, 0)) %>%
> + select.(c) %>%
> + as.data.table()
> + names(df_tmp) <- paste0(cols_tmp, "c")
> + res_df <- cbind(res_df, df_tmp)
> + }
> + return(res_df)
> + }
> >
> > #--- Sobre df creado
&g...