[R] Avoiding loops
dolar
nyetlin at gmail.com
Wed Sep 2 06:08:56 CEST 2009
Would like some tips on how to avoid loops as I know they are slow in R
i've got a data frame :
a b c
1 5 2
4 6 9
5 2 3
8 3 2
What i'd like is to sum for each value of a, the sum of b and the sum of c
where a equal to or less than (with a distance of 5)
i.e. for row three
we have a=5
i'd like to sum up b and sum up c with the above rule
since 5, 4 and 1 are less than (within a distance of 5) or equal to 5, then
we should get the following result:
a b c
5 13 14
the overall result should be
a b c
1 5 2
4 11 11
5 13 14
8 11 14
how can i do this without a loop?
--
View this message in context: http://www.nabble.com/Avoiding-loops-tp25251376p25251376.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list