This function is used when a single value has multiple flags. The same weight is repeated for each single character.
flag_divide(x)
x | A vector with two items. The first item is a string of flags with several characters, the second is a single numerical value of the weight. |
---|
flag_divide
returns a character matrix with the flags as single characters as the first column and the weight is
repeated as the second column. The length of the list is equal to the length of the string of flags.
flags <- tidyr::spread(test_data[, c(1:3)], key = time, value = flags) weights <- tidyr::spread(test_data[, c(1, 3:4)], key = time, value = values) input <- as.data.frame(cbind(flags[,5],weights[,5]),stringsAsFactors = FALSE)[!is.na(flags[,5]),] do.call(rbind, apply(input,1,flag_divide))#> f w #> 1.V11 d 10887.1564550837 #> 1.V12 e 10887.1564550837 #> 2.V11 b 9616.05052053671 #> 2.V12 u 9616.05052053671 #> 9 p 4718.17317480154 #> 15 e 8950.1386194342 #> 21 u 11687.8112265511 #> 26.V11 b 5283.5335695032 #> 26.V12 p 5283.5335695032 #> 27.V11 e 2809.95874942541 #> 27.V12 u 2809.95874942541