Using rapply one can write a function which runs over elements in a list returning a list.
# Here I create a list of 10 normal random numbers
testList <- list()
testList[[1]] <- rnorm(10)
testList[[2]] <- rnorm(10)
# Here I replace all numbers which are < 0 by 0
newList <- rapply(testList, function(x) {ifelse(x<0,0,x)}, how = "list")
Also if the data in the list is not a vector but a matrix
newList <- function="" ifelse="" lapply="" p="" sapply="" testlist="" x="" y="">
# Here I add all elements using the Reduce function
Reduce("+",newList)
Comments
Post a Comment