tidyr

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

Tidy method to split multiple columns using tidyr::separate

浪尽此生 提交于 2020-11-29 02:53:51
问题 I have a data frame like so: df <- structure(list(A = c("3 of 5", "1 of 2", "1 of 3", "1 of 3", "3 of 4", "2 of 7"), B = c("2 of 2", "2 of 4", "0 of 1", "0 of 0", "0 of 0", "0 of 0"), C = c("10 of 21", "3 of 14", "11 of 34", "10 of 35", "16 of 53", "17 of 62"), D = c("0 of 0", "0 of 0", "0 of 0", "0 of 0", "0 of 0", "0 of 0"), E = c("8 of 16", "3 of 15", "10 of 32", "6 of 28", "13 of 49", "9 of 48")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L)) df |A |B |C |D |E | |:----

Tidy method to split multiple columns using tidyr::separate

≯℡__Kan透↙ 提交于 2020-11-29 02:50:37
问题 I have a data frame like so: df <- structure(list(A = c("3 of 5", "1 of 2", "1 of 3", "1 of 3", "3 of 4", "2 of 7"), B = c("2 of 2", "2 of 4", "0 of 1", "0 of 0", "0 of 0", "0 of 0"), C = c("10 of 21", "3 of 14", "11 of 34", "10 of 35", "16 of 53", "17 of 62"), D = c("0 of 0", "0 of 0", "0 of 0", "0 of 0", "0 of 0", "0 of 0"), E = c("8 of 16", "3 of 15", "10 of 32", "6 of 28", "13 of 49", "9 of 48")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L)) df |A |B |C |D |E | |:----