data.table

Creating a new variable based on prior history

女生的网名这么多〃 提交于 2020-12-13 07:57:07
问题 I have data where I need to create a variable based on prior history, for example created<- c(2009,2010,2010,2011, 2012, 2011) person <- c(A, A, A, A, B, B) location<- c('London','Geneva', 'London', 'New York', 'London', 'London') df <- data.frame (created, person, location) I want to create a variable called 'existing' that takes into account the prior years and sees if he/she has lived in that place and gives a value of 0 if the place is old(and they lived there. Any suggestions? library

Creating a new variable based on prior history

为君一笑 提交于 2020-12-13 07:56:26
问题 I have data where I need to create a variable based on prior history, for example created<- c(2009,2010,2010,2011, 2012, 2011) person <- c(A, A, A, A, B, B) location<- c('London','Geneva', 'London', 'New York', 'London', 'London') df <- data.frame (created, person, location) I want to create a variable called 'existing' that takes into account the prior years and sees if he/she has lived in that place and gives a value of 0 if the place is old(and they lived there. Any suggestions? library

Creating a new variable based on prior history

别等时光非礼了梦想. 提交于 2020-12-13 07:56:01
问题 I have data where I need to create a variable based on prior history, for example created<- c(2009,2010,2010,2011, 2012, 2011) person <- c(A, A, A, A, B, B) location<- c('London','Geneva', 'London', 'New York', 'London', 'London') df <- data.frame (created, person, location) I want to create a variable called 'existing' that takes into account the prior years and sees if he/she has lived in that place and gives a value of 0 if the place is old(and they lived there. Any suggestions? library

Fill NA values with sequence by group

十年热恋 提交于 2020-12-05 11:36:25
问题 I am attempting to fill some values in a data set. A simplified version of my data can be found below: > example_df Date GROUP value 157 2018-01-31 10180 3.464 158 2018-02-28 10180 3.413 159 2018-03-31 10180 3.418 160 2018-04-30 10180 NA 161 2018-05-31 10180 NA 162 2018-06-30 10180 NA 163 2018-07-31 10180 NA 164 2018-08-31 10180 NA 165 2018-09-30 10180 NA 166 2018-10-31 10180 NA 167 2018-11-30 10180 NA 168 2018-12-31 10180 NA 169 2019-01-31 10180 NA 170 2019-02-28 10180 NA 171 2019-03-31

Fill NA values with sequence by group

女生的网名这么多〃 提交于 2020-12-05 11:33:56
问题 I am attempting to fill some values in a data set. A simplified version of my data can be found below: > example_df Date GROUP value 157 2018-01-31 10180 3.464 158 2018-02-28 10180 3.413 159 2018-03-31 10180 3.418 160 2018-04-30 10180 NA 161 2018-05-31 10180 NA 162 2018-06-30 10180 NA 163 2018-07-31 10180 NA 164 2018-08-31 10180 NA 165 2018-09-30 10180 NA 166 2018-10-31 10180 NA 167 2018-11-30 10180 NA 168 2018-12-31 10180 NA 169 2019-01-31 10180 NA 170 2019-02-28 10180 NA 171 2019-03-31

filter rows in data.table with `by`

有些话、适合烂在心里 提交于 2020-11-26 16:53:49
问题 I would like to filter group which following criteria. The DT brings unexpected results. Input data library(data.table) library(dplyr) dt <- data.table( logic = c(TRUE, TRUE, FALSE, TRUE, TRUE, TRUE), group = c("A" , "A", "A" , "B" , "B" , "B") ) I would like to filter group, where logic field values are all TRUE . Expected behavior (by dplyr ) As you can see dplyr works as expected, and brings back only values with group = B dt %>% group_by(group) %>% filter(all(logic)) # Source: local data

Sum amount last 6 month prior to the date of transaction

一个人想着一个人 提交于 2020-11-24 16:17:34
问题 This is my transaction data. It shows the transactions made from the accounts in from column to the accounts in to column with the date and the amount information data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1056317 7819 7454 2010-12-31 60.2 1056318 6164 7497 2010-12-31 107.5 1056319 7533 7492 2010-12-31 164.1 I want to calculate how much transaction amount the

Sum amount last 6 month prior to the date of transaction

微笑、不失礼 提交于 2020-11-24 16:10:58
问题 This is my transaction data. It shows the transactions made from the accounts in from column to the accounts in to column with the date and the amount information data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1056317 7819 7454 2010-12-31 60.2 1056318 6164 7497 2010-12-31 107.5 1056319 7533 7492 2010-12-31 164.1 I want to calculate how much transaction amount the

Sum amount last 6 month prior to the date of transaction

断了今生、忘了曾经 提交于 2020-11-24 16:10:48
问题 This is my transaction data. It shows the transactions made from the accounts in from column to the accounts in to column with the date and the amount information data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1056317 7819 7454 2010-12-31 60.2 1056318 6164 7497 2010-12-31 107.5 1056319 7533 7492 2010-12-31 164.1 I want to calculate how much transaction amount the

Sum amount last 6 month prior to the date of transaction

 ̄綄美尐妖づ 提交于 2020-11-24 16:10:27
问题 This is my transaction data. It shows the transactions made from the accounts in from column to the accounts in to column with the date and the amount information data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1056317 7819 7454 2010-12-31 60.2 1056318 6164 7497 2010-12-31 107.5 1056319 7533 7492 2010-12-31 164.1 I want to calculate how much transaction amount the