List comprehension in R
r
Solution
Something like this?
l <- 1:1000
sum(l[l %% 3 == 0 | l %% 5 == 0])
Problem
Is there a way to implement list comprehension in R? Like python: ``` sum([x for x in range(1000) if x % 3== 0 or x % 5== 0]) ``` same in Haskell: ``` sum [x| x<-[1..1000-1], x`mod` 3 ==0 || x `mod` 5 ==0 ] ``` What's the practical way to apply this in R? Nick