Ask Your Question
2

In R, what is the way to produce a list with lapply/sapply output?

asked 2023-07-15 09:20:02 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-15 09:30:01 +0000

plato gravatar image

To produce a list with lapply/sapply output in R, you can use the following syntax:

my_list <- lapply(my_vector, function(x) { # or sapply
  # code to process each element of my_vector
  # ...
  return(processed_value)
})

This will apply the specified function to each element of my_vector, and create a list my_list containing the processed values. You can also use unnamed functions for simpler operations:

my_list <- lapply(my_vector, sqrt) # or sapply

This will create a list of the square roots of each element of my_vector.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-15 09:20:02 +0000

Seen: 13 times

Last updated: Jul 15 '23