Questions tagged [mutated]

77 questions
12
votes
2 answers

RuntimeError: OrderedDict mutated during iteration (Python3)

Getting the error mentioned in the title. The below mentioned functioned is called by another function that is called through a POST api. Error is on the line below the print statement. Don't know what the error means and why its coming. The same…
SUP
  • 349
  • 1
  • 2
  • 11
6
votes
1 answer

R - allocate a share of a number over different columns using an ifelse statement

I have the following data set: observation <- c(1:10) pop.d.rank <- c(1:10) cost.1 <- c(101:110) cost.2 <- c(102:111) cost.3 <- c(103:112) all <- data.frame(observation,pop.d.rank,cost.1, cost.2, cost.3) And I want to allocate the following…
Thirst for Knowledge
  • 1,606
  • 2
  • 26
  • 43
3
votes
1 answer

dplyr transmute returning fewer rows than the original data frame

I need to get a summary of a grouped data set that is 4 rows (basically the square the would surround the set of data points in the subet of the data frame. A function: myfun <- function(F1,F2){ out <-structure(list(f2 = c(1097.81431421448,…
Fredrik Karlsson
  • 485
  • 8
  • 21
3
votes
2 answers

Mutate - NA Handling

I've used the arrange and mutate combination to do additions based on groupings. For example, I've used the following: master_df <-group_by(master_df,asof_dt) mutate(master_df,tot_flag=ls_flag) This groups my data frame master_df by asof_dt, and…
Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60
2
votes
1 answer

Strange error appearing in React Native: Collection NSSetM was mutated while being enumerated

I started getting strange error in React Native, usually in Modals. Sometimes it works, sometimes it can throw an error: Collections <_NSSetM was mutated while being enumerated. I am using expo 44.0.0. Here is my package.json file: { "scripts": { …
2
votes
2 answers

R mutate won't add columns

I am trying to use the mutate function to form three new columns to my data. I have tried defining some of the data and it has not changed it. I have looked at previous examples but all seem to use a group function before using mutate. I think I do…
hogballs96
  • 37
  • 3
2
votes
1 answer

How best a rename column values in R

So I have a column that reads as such. There are 12 values for each year. This continues from 2002 to 2022. The task that I am challenged with is how to make these appear like below. How would I do such a transformation? col_name 2002mq1m1 …
Tim Wilcox
  • 1,275
  • 2
  • 19
  • 43
2
votes
0 answers

What is the differance between dispatch_async and detachNewThreadSelector:@selector()

I've faced a crash in my app when using detachNewThreadSelector:@selector() under exception Collection was mutated while being enumerated also there are many of this exception This application is modifying the autolayout engine from a background…
Laith Mihyar
  • 891
  • 7
  • 7
2
votes
1 answer

merge or mutate a summary (dplyr)

I am always unsure how to retrieve a summary with dplyr. Let us suppose I have a summary of individuals and households. dta = rbind(c(1, 1, 45), c(1, 2, 47), c(2, 1, 24), c(2, 2, 26), c(3, 1, 67), c(4, 1, 20), c(4, 2, 21), c(5,…
giac
  • 4,261
  • 5
  • 30
  • 59
2
votes
2 answers

Filtering on a date using dplyr without changing the variable format

I want use a list of years to filter a database by date years<-c("2014") yearsdata <- data.frame(animal=c("cow","pig"), mydate=c(as.Date("2015-01-01"), as.Date("2014-01-01"))) yearsdata %>% …
BaconDoggie
  • 153
  • 3
  • 14
2
votes
1 answer

dictionaries and strings

This is my code that is not workin: def myfunc(d): for name, pat in d.items(): originalstring = pat pattern = '#\w+#' pattern_obj = re.compile(pattern) replacement_string = '('+d['\\1']+')' d[name] =…
1
vote
1 answer

keep the original value when using ifelse in dplyr after using cut

There is a dataset in which I have to create labels conditionally using the cut function; after that, only one of the labels shall be changed. Here is a similar code: data.frame(x = c(12, 1, 25, 12, 65, 2, 6, 17)) %>% mutate(rank = cut(x, breaks…
Abbas
  • 807
  • 7
  • 14
1
vote
1 answer

How do I use the dim function to evaluate another dataframe using mutate in r?

I am trying to add a column to a dataframe that has the dimension of a portion of another dataframe using the following code. library(dplyr) dfa <- data.frame(x=c(1,2,3,4,5), sym=c("a","a","b","b","b")) dfa <- dfa %>% group_by(sym) dfb <-…
M C
  • 21
  • 2
1
vote
2 answers

Mutate new column to create factor variable based on quantiles of other column, by group, in R

I have a panel data set with id, year and numerical column A. I want to add a column B with a factor variable indicating to which quantile group each row belongs per year, with either "lowest 33%", "33-67%" or "highest 33%". I played around with…
avocado1
  • 253
  • 2
  • 8
1
vote
1 answer

Set specific values of a group of variables to NA based on another group of variables

I could use some help with a tidyverse solution to this question. I'm working with a large dataset that has 20+ binary cancer outcomes (cancer_{cancertype}), as well as corresponding ages ({cancertype}_age). Some individuals are missing cancer…
1
2 3 4 5 6