Add list elments recursively

0 votes
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 in Data Analytics by anonymous
• 3,290 points
15 views

1 answer to this question.

0 votes

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
answered Oct 28 by Cherukuri
• 31,840 points

Related Questions In Data Analytics

0 votes
1 answer

How to provide names for list elments in r?

There are 2 ways to add names ...READ MORE

answered Oct 14 in Data Analytics by Cherukuri
• 31,840 points
19 views
+1 vote
1 answer

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

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
128 views
0 votes
1 answer

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

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

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,020 points
41 views
0 votes
1 answer

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

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

answered Apr 5, 2018 in Data Analytics by kappa3010
• 2,020 points
71 views
0 votes
1 answer

By using dpylr package sum of multiple columns

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

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
115 views
0 votes
1 answer

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

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

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
159 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

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

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points
86 views
0 votes
1 answer

How to create a list of Data frames?

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

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
104 views
0 votes
1 answer

How to add elements into a list in R?

hey, Add elements into list as below. list = ...READ MORE

answered Sep 30 in Data Analytics by anonymous
• 31,840 points
21 views
0 votes
1 answer

How to add special characters to a list?

@ch, You can add $. , / using ...READ MORE

answered Oct 14 in Data Analytics by anonymous
• 31,840 points
15 views