Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a function like this:
a <- list() a$prod_1 <- c(1,2,3) a$prod_2 <- c(4,5,6)
and I want to exponentiante each element of the list I tried something like this:
exp_a <- lapply(a, funtion(x) e^x)
lapply(a, exp)
e doesn't exist as a constant in R, but the exponential function does. Just use exp_a <- lapply(a, exp)
e
exp
exp_a <- lapply(a, exp)
Add a comment
You have a couple of ways to make it, while below are just two examples:
exp_a <- Map(exp,a)
or
exp_a <- as.list(as.data.frame(exp(do.call(cbind,a))))
We can use map from purrr
map
purrr
library(purrr) map(a, exp)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
lapply(a, exp)will return a list of exponentiated vectors.