Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
  2.  
  3. get_price_by_category <- function(dataset, x, y) {
  4. print(c(x, typeof(x)))
  5. dataset %>% filter(carat == x) %>% print()
  6. }
  7.  
  8. carats %>% walk(get_price_by_category, dataset = diamonds, y= "price")
  9.  
  10. [1] "0.2" "double"
  11. # A tibble: 0 x 10
  12. # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
  13. # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
  14. [1] "0.21" "double"
  15. # A tibble: 0 x 10
  16. # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
  17. # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
  18. [1] "0.22" "double"
  19. # A tibble: 0 x 10
  20. # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
  21. # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
  22. [1] "0.23" "double"
  23. # A tibble: 0 x 10
  24. # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
  25. # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
  26. ...
  27.  
  28. carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
  29.  
  30. get_price_by_category <- function(dataset, x, y) {
  31. print(c(x, typeof(x)))
  32. dataset %>% filter(carat == x) %>% print()
  33. }
  34.  
  35. for (c in carats) {
  36. get_price_by_category(diamonds, c, y= "price")
  37. }
  38.  
  39. carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
  40.  
  41. get_price_by_category <- function(dataset, x, y) {
  42. print(c(c, typeof(c)))
  43. dataset %>% filter(carat == c) %>% print()
  44. }
  45.  
  46. for (c in carats) {
  47. get_price_by_category(diamonds, c, y= "price")
  48. }
  49.  
  50. [1] "0.2" "double"
  51. # A tibble: 12 x 10
  52. carat cut color clarity depth table price x y z
  53. <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
  54. 1 0.2 Premium E SI2 60.2 62 345 3.79 3.75 2.27
  55. 2 0.2 Premium E VS2 59.8 62 367 3.79 3.77 2.26
  56. 3 0.2 Premium E VS2 59 60 367 3.81 3.78 2.24
  57. 4 0.2 Premium E VS2 61.1 59 367 3.81 3.78 2.32
  58. 5 0.2 Premium E VS2 59.7 62 367 3.84 3.8 2.28
  59. 6 0.2 Ideal E VS2 59.7 55 367 3.86 3.84 2.3
  60. 7 0.2 Premium F VS2 62.6 59 367 3.73 3.71 2.33
  61. 8 0.2 Ideal D VS2 61.5 57 367 3.81 3.77 2.33
  62. 9 0.2 Very Good E VS2 63.4 59 367 3.74 3.71 2.36
  63. 10 0.2 Ideal E VS2 62.2 57 367 3.76 3.73 2.33
  64. 11 0.2 Premium D VS2 62.3 60 367 3.73 3.68 2.31
  65. 12 0.2 Premium D VS2 61.7 60 367 3.77 3.72 2.31
  66. [1] "0.21" "double"
  67. # A tibble: 9 x 10
  68. carat cut color clarity depth table price x y z
  69. <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
  70. 1 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
  71. 2 0.21 Very Good E VS2 63.2 54 386 3.82 3.78 2.4
  72. 3 0.21 Premium E VS2 60.5 59 386 3.87 3.83 2.33
  73. 4 0.21 Premium E VS2 59.6 56 386 3.93 3.89 2.33
  74. 5 0.21 Premium D VS2 61.6 59 386 3.82 3.78 2.34
  75. 6 0.21 Premium D VS2 60.6 60 386 3.85 3.81 2.32
  76. 7 0.21 Premium D VS2 59.1 62 386 3.89 3.86 2.29
  77. 8 0.21 Premium D VS2 58.3 59 386 3.96 3.93 2.3
  78. 9 0.21 Premium E SI2 61.9 56 394 3.84 3.82 2.37
  79. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement