search for: left_join

Displaying 20 results from an estimated 21 matches for "left_join".

2017 Mar 15
3
Crear una función
...la[, PorcAc := cumsum(Porc)] # Regiones tabla.1 <- datos[, .N, by = .(etiqueta = x, Region)] tabla.1[, Porc := round(N/sum(N)*100,1), by =.(Region)] tabla.1 <- spread(tabla.1[, .(etiqueta, Region, Porc)], key = Region, value = Porc) tabla.reg <- left_join(tabla, tabla.1) # Depdendencia tabla.1 <- datos[, .N, by = .(etiqueta = x, Dependencia = B2a)] tabla.1[, Porc := round(N/sum(N)*100,1), by =.(Dependencia)] # % por Dependencia tabla.1 <- na.omit(tabla.1) tabla.1 <- spread(tabla.1[, .(etique...
2017 Mar 15
4
Fwd: Crear una función
...[, PorcAc := cumsum(Porc)]           # Regiones           tabla.1 <- datos[, .N, by = .(etiqueta = x, Region)]            tabla.1[, Porc := round(N/sum(N)*100,1), by =.(Region)]            tabla.1 <- spread(tabla.1[, .(etiqueta, Region, Porc)], key = Region, value = Porc)      tabla.reg <- left_join(tabla, tabla.1)           # Depdendencia           tabla.1 <- datos[, .N, by = .(etiqueta = x, Dependencia = B2a)]            tabla.1[, Porc := round(N/sum(N)*100,1), by =.(Dependencia)] # % por Dependencia           tabla.1 <- na.omit(tabla.1)           tabla.1 <- spread(tabla.1[, .(etiqu...
2023 Jun 29
0
Processing a hierarchical string name
...for your help. Ivan, your solution worked perfectly. I didn't really understand how to do string processing on a vector of strings, and your solution demonstrated it for me. I modified it to work with the tidyverses' stringr library in this way: bg3_race_sum <- bg3_race %>% left_join(pl_vars, by=c("variable" = "name")) %>% group_by(variable) %>% summarize(count = sum(value)) %>% left_join(pl_vars, by=c("variable" = "name")) %>% filter(count > 0) %>% .$label %>% str_replace("^ !!&quot...
2017 Sep 04
1
Dataframe Manipulation
...n it i can use it in future by doing some Lil bit manipulation. Thanks data_help <- data_help %>% mutate(Purchase_ID = 1:n()) %>% group_by(Purchase_ID) %>% do(split_items(.)) cat_help %>% gather("Foo", "Item") %>% filter(!is.na(Item)) %>% left_join(data_help, by = "Item") %>% group_by(Foo, Purchase_ID) %>% summarise(Item = paste(Item, collapse = ", ")) %>% spread(key = "Foo", value = "Item") On 31 August 2017 at 13:17, Ulrik Stervbo <ulrik.stervbo at gmail.com> wrote: > Hi Hema...
2018 Mar 22
1
Calculate weighted proportions for several factors at once
...=30)) %>% tbl_df() # instead of doing this separately for each factor ... df2 <- df1 %>% group_by(group) %>% dplyr::count(var1, wt=wt) %>% mutate(prop1=n/sum(n)) df3 <- df1 %>% group_by(group) %>% dplyr::count(var2, wt=wt) %>% mutate(prop2=n/sum(n)) %>% left_join(df2, by='group') # I would like to do something like the following (which does of course not work): my_fun <- function(x,wt){ freq1 <- dplyr::count(x, wt=wt) prop1 <- freq1 / sum(freq1) return(prop) } df1 %>% group_by(group) %>% summarise_all(.funs=my_fun(.), .var...
2016 Feb 29
4
Juntar dos data.frames eliminando celdas con NA
Hola a todos, Quisiera juntar las informacion de dos data.frames con una union de columnas un tanto especial. La informacion que tengo son datos de captura-recaptura de diferentes individuos, por ejemplo en una base de datos tengo:ID <- c(1,2,3,4)Fate_1 <- c(2,2,2,2)Fate_2 <- c(0,0,0,NA)Fate_3 <- c(0, NA, NA, NA) y en otra base de datos tengo:ID <- c(1,2,3)Fate_1 <- c(0, 0, 0,
2019 Oct 07
4
[External] Re: should base R have a piping operator ?
> On 7 Oct 2019, at 17:04, Tierney, Luke <luke-tierney at uiowa.edu> wrote: > > Think about what happens if an > argument in a pipe stage contains a pipe. (Not completely > unreasonable, e.g. for a left_join). It should work exactly as it does in a local environment. ``` `%foo%` <- function(x, y) { env <- parent.frame() # Use `:=` to avoid partial matching on .env/.frame rlang::scoped_bindings(. := x, .env = env) eval(substitute(y), env) } "A" %foo% { print(.) "B&q...
2018 Feb 22
3
Filtrado de variables
Buenos díasTengo esta pequeña matriz con tres columnas. Querría saber como puedo filtrar el mes en el que todos los campos de la columna RESULTADO son NA  (en este caso sería unicamente el mes 4). Gracias  | MES | VARIABLE | RESULTADO | | 1 | A | SI | | 1 | B | SI | | 1 | C | NO | | 2 | A | NA | | 2 | B | SI | | 2 | C | SI | | 3 | A | NO | | 3 | B | NO | | 3 | C | NO | | 4 | A | NA | | 4 | B | NA
2017 Aug 31
0
Dataframe Manipulation
...ames = FALSE) data_frame(Item = x, Purchase_ID = items$Purchase_ID) } data_help <- data_help %>% mutate(Purchase_ID = 1:n()) %>% group_by(Purchase_ID) %>% do(split_items(.)) cat_help %>% gather("Foo", "Item") %>% filter(!is.na(Item)) %>% left_join(data_help, by = "Item") %>% group_by(Foo, Purchase_ID) %>% summarise(Item = paste(Item, collapse = ", ")) %>% spread(key = "Foo", value = "Item") HTH Ulrik On Wed, 30 Aug 2017 at 13:22 Hemant Sain <hemantsain55 at gmail.com> wrote: &gt...
2017 Aug 30
1
Dataframe Manipulation
...>> table_1 <- gather(table_1, "Foo", "Item") %>% >> filter(!is.na(Item)) >> >> table_1 <- separate(table_1, col = "Item", into = c("Quantity", "Item"), >> sep = " ") >> >> table_3 <- left_join(table_1, table_2, by = "Item") %>% >> mutate(Item = paste(Quantity, Item)) %>% >> select(-Quantity) >> >> table_3 %>% >> group_by(Foo, Category) %>% >> summarise(Item = paste(Item, collapse = ", ")) %>% >> spread...
2020 Sep 22
3
EXTRAER MES EN LETRAS Y CASTELLANO
Buenas tardes, Estoy precisando generar una nueva variable que contenga el mes en tres letras, por ejemplo: ENE , FEB, MAR , ABR y así sucesivamente a partir de los valores que ahora tengo en el Dataset, que son 1, 2, 3, 4 y así sucesivamente. Entiendo que sería con mutate, pero consulto acerca del comando completo.. Gracias, Jesús _________________ *Jesús MARTÍN FRADE * Skype:
2018 Mar 19
1
Labelling a fortified GADM map plotted with ggplot and geom_map
...mes(kids_province_data)[2] <- "Number" # sum the data by province kids_province_sums <- aggregate(.~Province, data = kids_province_data, sum) # join the data to the map names(tract)[6] <- "region" names(kids_province_sums)[1] <- "region" by_province <- left_join(tract, kids_province_sums) # create the data map kids_map <- ggplot(by_province, aes(map_id = region)) + #plots the map in by_province separating by region geom_map(aes(fill = Number), #generates aestheticsa for the plot ma...
2020 Jun 26
4
Quedarse con las muestras de una BD que están presentes otra, basado en dos variables
Buenas tardes, quedarme con las muestras de una BD (data) que están presentes en otra (datax), cuando se tiene una variable que nunca se repite (Key) es fácil: data <- subset(data,data$Key %in% datax$Key). Mi problema es cuando la exclusividad viene dada por dos variables. P.e., las coordenadas de un mapa: lon y lat. ¿Como puedo quedarme con las muestras de una df cuya lon y lat son iguales a
2019 Oct 07
0
[External] Re: should base R have a piping operator ?
On Mon, 7 Oct 2019, Lionel Henry wrote: > > >> On 7 Oct 2019, at 17:04, Tierney, Luke <luke-tierney at uiowa.edu> wrote: >> >> Think about what happens if an >> argument in a pipe stage contains a pipe. (Not completely >> unreasonable, e.g. for a left_join). > > It should work exactly as it does in a local environment. > > ``` > `%foo%` <- function(x, y) { > env <- parent.frame() > > # Use `:=` to avoid partial matching on .env/.frame > rlang::scoped_bindings(. := x, .env = env) > > eval(substitute(y), env)...
2023 Nov 04
1
Adding columns to a tibble based on a value in a different tibble
I think a simple reproducible example ("reprex") may be necessary for you to get a useful reply. Questions with vague specifications such as yours often result in going round and round with attempts to clarify what you mean without a satisfactory answer. Clarification at the outset with a reprex may save you and others a lot of frustration. Cheers, Bert On Sat, Nov 4, 2023 at 1:41?AM
2017 Oct 09
3
Merge me agrega siempre las columnas
Buenas, Tengo dos data.frames de la siguiente manera library(data.table) id<-c("a1","a2","a3","a4") id2<-c("a2","a3","a1","a4") y<-c(1,2,3,4) z<-c(3,5,6,7) k<-c(1,3,8,7) df1<-data.table(id,y,z) id<-c("a2","a3","a1","a4") df2<-data.table(id,x,y) Quiero
2019 Oct 07
0
[External] Re: should base R have a piping operator ?
...in `on.exit()` (or through > unwind-protection if implemented in C). > Sorry to be blunt but adding/removing a variable from a caller's environment is a horrible design idea. Think about what happens if an argument in a pipe stage contains a pipe. (Not completely unreasonable, e.g. for a left_join). We already have such a design lurking in (at least) one place in base code and it keeps biting. It's pretty high on my list to be expunged. If a variable is to be used it needs to be in its own scope/environment. There is another option, which is to rewrite the pipe as a nested call and eva...
2019 Oct 07
4
should base R have a piping operator ?
Hi Gabe, > There is another way the pipe could go into base R that could not be > done in package space and has the potential to mitigate some pretty > serious downsides to the pipes relating to debugging I assume you're thinking about the large stack trace of the magrittr pipe? You don't need a parser transformation to solve this problem though, the pipe could be implemented as
2018 May 01
0
how can I convert a long to wide matrix?
Hi Marna, This is a condition that the function cannot handle. It would be possible to reformat the result based on the time intervals, but the stretch_df function doesn't try to interpret the values, just stretches them out to a wide format. Jim On Wed, May 2, 2018 at 9:16 AM, Marna Wagley <marna.wagley at gmail.com> wrote: > Hi Jim, > The data set is correct. I took two
2017 Aug 30
3
Dataframe Manipulation
Hey PIKAL, It's not a homework neithe that is the real dataset i have signer NDA for my company so that i can share the original data file, Actually I'm working on a market basket analysis task but not able to convert my existing data table to appropriate format so that i can apply Apriori algorithm using R, and this is very important me to get it done because I'm an intern and if i