data <- read_excel("../00_data/myData.xlsx")
data <- as_tibble(data)
Case of numeric variables
data %>% map_dbl(.x = ., .f = ~mean(x = .x))
## Warning in mean.default(x = .x): argument is not numeric or logical: returning
## NA
## stock_symbol date open high low close
## NA 1.470239e+09 8.926658e+01 9.036983e+01 8.811193e+01 8.927131e+01
## adj_close volume
## 8.520963e+01 5.297813e+07
data %>% map_dbl(.x = ., .f = ~mean(x = .x))
## Warning in mean.default(x = .x): argument is not numeric or logical: returning
## NA
## stock_symbol date open high low close
## NA 1.470239e+09 8.926658e+01 9.036983e+01 8.811193e+01 8.927131e+01
## adj_close volume
## 8.520963e+01 5.297813e+07
data %>% map_dbl(mean)
## Warning in mean.default(.x[[i]], ...): argument is not numeric or logical:
## returning NA
## stock_symbol date open high low close
## NA 1.470239e+09 8.926658e+01 9.036983e+01 8.811193e+01 8.927131e+01
## adj_close volume
## 8.520963e+01 5.297813e+07
#Adding an argument
data %>% map_dbl(.x = ., .f = ~mean(x = .x, trim = 0.1))
## Warning in mean.default(x = .x, trim = 0.1): argument is not numeric or
## logical: returning NA
## stock_symbol date open high low close
## NA 1.470621e+09 6.904538e+01 6.981399e+01 6.826350e+01 6.906325e+01
## adj_close volume
## 6.407346e+01 3.421923e+07
data %>% map_dbl(mean, trim = 0.1)
## Warning in mean.default(.x[[i]], ...): argument is not numeric or logical:
## returning NA
## stock_symbol date open high low close
## NA 1.470621e+09 6.904538e+01 6.981399e+01 6.826350e+01 6.906325e+01
## adj_close volume
## 6.407346e+01 3.421923e+07
data %>% select(.data = .,high)
## # A tibble: 45,088 × 1
## high
## <dbl>
## 1 7.66
## 2 7.70
## 3 7.69
## 4 7.57
## 5 7.57
## 6 7.61
## 7 7.49
## 8 7.53
## 9 7.52
## 10 7.56
## # ℹ 45,078 more rows
data %>% select(high)
## # A tibble: 45,088 × 1
## high
## <dbl>
## 1 7.66
## 2 7.70
## 3 7.69
## 4 7.57
## 5 7.57
## 6 7.61
## 7 7.49
## 8 7.53
## 9 7.52
## 10 7.56
## # ℹ 45,078 more rows
Create your own function
# Double values in columns
# double_by_factor <- function(x, factor) {x * factor}
#10 %>% double_by_factor(factor = 2)
#data %>% map_dfr(.x = ., .f = ~double_by_factor(x = .x, factor = 10))
#data %>% map_dfr(double_by_factor, factor = 10)
When you have a grouping variable (factor)
Choose either one of the two cases above and apply it to your data