Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
- get_price_by_category <- function(dataset, x, y) {
- print(c(x, typeof(x)))
- dataset %>% filter(carat == x) %>% print()
- }
- carats %>% walk(get_price_by_category, dataset = diamonds, y= "price")
- [1] "0.2" "double"
- # A tibble: 0 x 10
- # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
- # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
- [1] "0.21" "double"
- # A tibble: 0 x 10
- # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
- # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
- [1] "0.22" "double"
- # A tibble: 0 x 10
- # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
- # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
- [1] "0.23" "double"
- # A tibble: 0 x 10
- # … with 10 variables: carat <dbl>, cut <ord>, color <ord>, clarity <ord>,
- # depth <dbl>, table <dbl>, price <int>, x <dbl>, y <dbl>, z <dbl>
- ...
- carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
- get_price_by_category <- function(dataset, x, y) {
- print(c(x, typeof(x)))
- dataset %>% filter(carat == x) %>% print()
- }
- for (c in carats) {
- get_price_by_category(diamonds, c, y= "price")
- }
- carats <- pull(diamonds %>% distinct(carat) %>% arrange(carat))
- get_price_by_category <- function(dataset, x, y) {
- print(c(c, typeof(c)))
- dataset %>% filter(carat == c) %>% print()
- }
- for (c in carats) {
- get_price_by_category(diamonds, c, y= "price")
- }
- [1] "0.2" "double"
- # A tibble: 12 x 10
- carat cut color clarity depth table price x y z
- <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
- 1 0.2 Premium E SI2 60.2 62 345 3.79 3.75 2.27
- 2 0.2 Premium E VS2 59.8 62 367 3.79 3.77 2.26
- 3 0.2 Premium E VS2 59 60 367 3.81 3.78 2.24
- 4 0.2 Premium E VS2 61.1 59 367 3.81 3.78 2.32
- 5 0.2 Premium E VS2 59.7 62 367 3.84 3.8 2.28
- 6 0.2 Ideal E VS2 59.7 55 367 3.86 3.84 2.3
- 7 0.2 Premium F VS2 62.6 59 367 3.73 3.71 2.33
- 8 0.2 Ideal D VS2 61.5 57 367 3.81 3.77 2.33
- 9 0.2 Very Good E VS2 63.4 59 367 3.74 3.71 2.36
- 10 0.2 Ideal E VS2 62.2 57 367 3.76 3.73 2.33
- 11 0.2 Premium D VS2 62.3 60 367 3.73 3.68 2.31
- 12 0.2 Premium D VS2 61.7 60 367 3.77 3.72 2.31
- [1] "0.21" "double"
- # A tibble: 9 x 10
- carat cut color clarity depth table price x y z
- <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
- 1 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
- 2 0.21 Very Good E VS2 63.2 54 386 3.82 3.78 2.4
- 3 0.21 Premium E VS2 60.5 59 386 3.87 3.83 2.33
- 4 0.21 Premium E VS2 59.6 56 386 3.93 3.89 2.33
- 5 0.21 Premium D VS2 61.6 59 386 3.82 3.78 2.34
- 6 0.21 Premium D VS2 60.6 60 386 3.85 3.81 2.32
- 7 0.21 Premium D VS2 59.1 62 386 3.89 3.86 2.29
- 8 0.21 Premium D VS2 58.3 59 386 3.96 3.93 2.3
- 9 0.21 Premium E SI2 61.9 56 394 3.84 3.82 2.37
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement