search for: case_when

Displaying 14 results from an estimated 14 matches for "case_when".

2023 Mar 21
1
preguntas múltiples y creación de variables
...quot;,access="p5.5",oracle="p5.6",mysql="p5.7",postgre_sql="p5.8"))* > > Me queda así > > [image: image.png] > > El tema es que cuándo quiero correr el siguiente código: > > > > > > > > *mutate(puntaje_p4_p5=case_when(p4_bases_prop==1 & p5.1==1 ~ 0.4, >                        p4_bases_prop==1 & p5.2==1 ~ 0.5, >              (p4_bases_prop==1) & ((p5.1==1) & (p5.3==1) | (p5.4==1) | > (p5.6=1) | (p5.7==1) | (p5.8==1)) ~  1, >  (p4_bases_prop==1) & ((p5.2==1) & (p5.3==1) | (p5.4=...
2023 Mar 07
1
reemplazar valores en texto según condiciones
Hola, La función case_when() te puede servir https://dplyr.tidyverse.org/reference/case_when.html El mar, 7 mar 2023 a las 12:04, juan manuel dias (<juamadias en gmail.com>) escribió: > Hola, como andan! Espero que bien! > Tengo dos bases, A) tiene una variable texto en la que deseo reemplazar > ciertas p...
2023 Nov 04
2
I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
...quot;Male"=65, "Female"=58)) # do the maths myDf$LAP <- (myDf$WC - as.numeric(myDf$GF))* myDf$TG #show results head(myDf) gender WC TG GF LAP 1 Male 70 0.9 58 61.2 2 Female 60 1.1 65 64.9 3 Male 75 1.2 58 87.6 4 Female 65 1.0 65 64.0 (Reality: I'd have probably used case_when in tidy to create a new numeric column) The equation to > calculate LAP is different for male and females. I am giving both equations > below. > > LAP for male = (WC-65)*TG > LAP for female = (WC-58)*TG > > My question is 'how can I calculate the LAP and create a singl...
2023 Mar 07
1
reemplazar valores en texto según condiciones
Hola, como andan! Espero que bien! Tengo dos bases, A) tiene una variable texto en la que deseo reemplazar ciertas partes y B) tengo las condiciones para cambiar ese texto de la base A. Base A texto si p1 = 1 o 2 = 1,3 si p1 = 3 o 4 = 1 si p1 = 5 = 0,7 si p1 = 5 = 0,7 si p1 = 6 = 0 si p1 = 7 = "no aplica" si p2 = 1 & p3 = 1 = 0,5 si p2 = 1 & p3 = 2 = 0,7 si p2 = 1 & p3 = 4
2023 Nov 05
1
I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
...Male"=65, "Female"=58)) # do the maths myDf$LAP <- (myDf$WC - as.numeric(myDf$GF))* myDf$TG #show results head(myDf) gender WC TG GF LAP 1 Male 70 0.9 58 61.2 2 Female 60 1.1 65 64.9 3 Male 75 1.2 58 87.6 4 Female 65 1.0 65 64.0 (Reality: I'd have probably used case_when in tidy to create a new numeric column) The equation to calculate LAP is different for male and females. I am giving both equations below. LAP for male = (WC-65)*TG LAP for female = (WC-58)*TG My question is 'how can I calculate the LAP and create a single new column? [[alternative...
2023 Mar 20
1
preguntas múltiples y creación de variables
...;p5.2",sql_server_microsoft="p5.3",mongo_db="p5.4",access="p5.5",oracle="p5.6",mysql="p5.7",postgre_sql="p5.8"))* Me queda así [image: image.png] El tema es que cuándo quiero correr el siguiente código: *mutate(puntaje_p4_p5=case_when(p4_bases_prop==1 & p5.1==1 ~ 0.4, p4_bases_prop==1 & p5.2==1 ~ 0.5, (p4_bases_prop==1) & ((p5.1==1) & (p5.3==1) | (p5.4==1) | (p5.6=1) | (p5.7==1) | (p5.8==1)) ~ 1, (p4_bases_prop==1) & ((p5.2==1) & (p5.3==1) | (p5.4==1) | (p5.6=1) | (p5...
2023 Jan 05
1
R 'arima' discrepancies
...=======# #Data ---- #============================================================# #Brazilian CPI and analytical components ipca <- gbcbd_get_series(c(433, 4449, 10844, 11428, 27863, 27864), first.date = dmy("01/01/2004")) ipca <- ipca %>% mutate(series.name = case_when(id.num == 433 ~ "ipca", id.num == 4449 ~ "administrados", id.num == 10844 ~ "servicos", id.num == 11428 ~ "livres", id.num == 27863 ~ "industriais", id.num == 27864 ~ "alimentos", TRUE ~ series.name)) ipca <- ipca %>% sel...
2023 Nov 03
1
[EXTERNAL] RE: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
Yes, that will halve the number of multiplications. If you?re looking for such optimisations then you can also consider ifelse(G=='male', 65L, 58L). That will definitely use less time & memory if WC is integer, but the trade-offs are more complicated if WC is floating point. Regards, Jorgen Harmse. From: avi.e.gross at gmail.com <avi.e.gross at gmail.com> Date: Friday,
2023 Mar 20
1
preguntas múltiples y creación de variables
...;p5.2",sql_server_microsoft="p5.3",mongo_db="p5.4",access="p5.5",oracle="p5.6",mysql="p5.7",postgre_sql="p5.8"))* Me queda así [image: image.png] El tema es que cuándo quiero correr el siguiente código: *mutate(puntaje_p4_p5=case_when(p4_bases_prop==1 & p5.1==1 ~ 0.4, p4_bases_prop==1 & p5.2==1 ~ 0.5, (p4_bases_prop==1) & ((p5.1==1) & (p5.3==1) | (p5.4==1) | (p5.6=1) | (p5.7==1) | (p5.8==1)) ~ 1, (p4_bases_prop==1) & ((p5.2==1) & (p5.3==1) | (p5.4==1) | (p5.6=1) | (p5...
2019 May 17
5
Give update.formula() an option not to simplify or reorder the result -- request for comments
Dear All, Martin Maechler has asked me to send this to R-devel for discussion after I submitted it as an enhancement request ( https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17563). At this time, the update.formula() method always performs a number of transformations on the results, eliminating redundant variables and reordering interactions to be after the main effects. This is not always
2023 Nov 03
2
I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
Just a minor point in the suggested solution: df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) since WC and TG are not conditional, would this be a slight improvement? df$LAP <- with(df, TG*(WC - ifelse(G=='male', 65, 58))) -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Jorgen Harmse via R-help Sent: Friday,
2024 May 25
1
dplyr, group_by and selective action according to each group
Although there may well be many ways to do what is being asked for with the tidyverse, sometimes things are simple enough to do the old-fashioned way. The request seems to have been to do something to all rows in ONE specific group but was phrased in the sense of wanting to know which group your functionality is being called in. What grouping gains you is more worthwhile if you are interested in
2018 Feb 26
0
alternative for multiple if_else statements
That many ifelse statements is obviously rather a pain. Would you not have got what you want with ... paste("survey", year, sep="_") ? If that is not what you're looking for (eg because 'year' is the observation year and not the study start year), perhaps something that picks the minimum year for a subject or other relevant group might work? For example
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-defined one year follow up (which we called