Summing part of a string

I have the following data and want to sum only the first 25 values so that I may preform the Mann-Whitney U test on it. Does anyone know how to sum only the first half of this string?
avg<- c(1,1,2,3,4,5,2,4,5,7,2,4,5,7,2,7,5,8,2,5,2,9,5,3,2,7,2,1,6,8,3,2,1,3,6,8,3,4,9,1,2,4,6,1,5, 6, 2, 7, 8, 1)

i.e. I would like the sum of 1,1,2,3,4,5,2,4,5,7,2,4,5,7,2,7,5,8,2,5,2,9,5,3,2 without simply copying & pasting those values and placing them in sum()

This should get you what you want.

sum(avg[1:25])

Do you need a more general solution or is summing the first 25 elements a good enough solution?

That's good. Thank you, I was using parentheses instead of brackets. Silly mistake!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.