Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. df1 df2
  2. Geogkey Brand Week date Impressions
  3. TMZ43434 x 6/16/18 6/14/18 798798
  4. KRO36783 y 6/16/18 6/21/18 562314
  5. .... 6/28/18 462534
  6. n
  7.  
  8. Geogkey date Impressions
  9. TMZ43434 6/14/18 798798
  10. TMZ43434 6/21/18 562314
  11. TMZ43434 6/28/18 462534
  12. KRO36783 6/14/18 798798
  13. KRO36783 6/21/18 562314
  14. KRO36783 6/28/18 462534
  15.  
  16. empty <- data.frame(df2$date, df2$impressions)
  17.  
  18. #creates a new data frame with unique geogkeys
  19. geogname <- unique(data.frame(df1$GEOGKEY))
  20.  
  21. #create some function that will index each unique geogkey and make a new
  22. column for df2 with that name (e.g. df2$geogkey <- some function)
  23.  
  24. new_df <- rbind(empty, df2)
  25. #this should theoretically append all the geogkeys to the dates and
  26. impressions
  27.  
  28. df <- data.frame()
  29. for(i in unique(df1$GEOKEY){
  30. for(j in 1:nrow(df2)){
  31.  
  32. df <- rbind(df,
  33. data.frame('key' = i, 'date' = df2[j,1], 'impressions' = df2[j,2]))
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement