Hello, list, I've been struggling with this task for a while looking for an efficient way to solve it: There are two variables 'price' and 'mentioned'. I want to 'enlarge' data so that missing price points within the price range are added to variable price. Also variable 'mentioned' is to receive values 0 in these cases. Note: Price points in original data can repeat if several persons mentioned that price point. Example: a) Original data: price mentioned 0,00 1 0,00 1 0,02 1 0,03 1 0,03 1 0,04 1 0,10 1 0,16 1 0,19 1 0,19 1 price range is 0,00 - 0,19. Some prices are missing, e.g. 0,01 . b) Supplemented data: price mentioned 0,00 1 0,00 1 0,01 0 0,02 1 0,03 1 0,03 1 0,04 1 0,05 0 0,06 0 0,07 0 0,08 0 0,09 0 0,10 1 0,11 0 0,12 0 0,13 0 0,14 0 0,15 0 0,16 1 0,17 0 0,18 0 0,19 1 0,19 1 0,20 0 Any ideas are welcome. Thanks a lot, Mario Aachen, Germany [[alternative HTML version deleted]]
Milan Bouchet-Valat
2011-Nov-18 17:05 UTC
[R] Filling a variable with unmentioned categories
Le vendredi 18 novembre 2011 ? 15:06 +0000, Mario Giesel a ?crit :> Hello, list, > > I've been struggling with this task for a while looking for an efficient way to solve it: > There are two variables 'price' and 'mentioned'. > I want to 'enlarge' data so that missing price points within the price range are added to variable price. > Also variable 'mentioned' is to receive values 0 in these cases. > Note: Price points in original data can repeat if several persons mentioned that price point.Let's say prices1 holds the first list of prices, prices2 the supplementary one. Try: prices <- c(prices1, prices2) prices <- sort(prices[!duplicated(prices)]) data.frame(price=prices, mentioned=prices %in% prices1) Regards