How to find the sum of nested list elements?

I tried sum function but doesn't work for finding the sum of a nested list.
Oct 23, 2019 619 views

## 1 answer to this question.

You cannot use the sum function on nested lists. If you want to find the total sum of nested list elements the unlist the nested lists and then use sum function.

> list(1,1:5,6)
[[1]]
[1] 1

[[2]]
[1] 1 2 3 4 5

[[3]]
[1] 6

> sum(list(1,1:5,6))
Error in sum(list(1, 1:5, 6)) : invalid 'type' (list) of argument
> sum(unlist(list(1,1:5,6)))
[1] 22
• 33,030 points

+1 vote

## How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

## How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

## How to join two tables (tibbles) by *list* columns in R

You can use the hash from digest ...READ MORE

## By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

## How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

## In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

## How to create a list of Data frames?

Basically all we have to do is ...READ MORE