I want to expand my existing function which returns a column of values.
library(tidyverse)
some_function <- function(cost, rbf_sigma){
cost + rbf_sigma
}
tibble(cost = 1:5,
rbf_sigma = 11:15) %>%
mutate(val1 = map2_dbl(cost, rbf_sigma, some_function))
So, this function returns:
# A tibble: 5 x 3
cost rbf_sigma val1
<int> <int> <dbl>
1 1 11 12
2 2 12 14
3 3 13 16
4 4 14 18
5 5 15 20
And this is a function that returns two columns:
some_function2 <- function(cost, rbf_sigma){
value1 <- cost + 1
value2 <- rbf_sigma + 3
tibble(value1, value2)
}
So, I want to apply this function as before, more or less like this (this of course produces an error and the part that I am stuck):
tibble(cost = 1:5,
rbf_sigma = 11:15) %>%
mutate(val1 = map2_dbl(cost, rbf_sigma, some_function)$value1,
val2 = map2_dbl(cost, rbf_sigma, some_function)$value1)
I want the result to be something like this:
# A tibble: 5 x 4
cost rbf_sigma val1 val2
<int> <int> <dbl> <dbl>
1 1 11 2 14
2 2 12 3 15
3 3 13 4 16
4 4 14 5 17
5 5 15 6 18
Any idea how to do this? Thanks and appreciate any help.