List comprehension in R

前端 未结 7 1534
执笔经年
执笔经年 2020-12-24 11:48

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 H

相关标签:
7条回答
  • 2020-12-24 12:15

    Yes, list comprehension is possible in R:

    sum((1:1000)[(1:1000 %% 3) == 0 | (1:1000 %% 5) == 0])
    
    0 讨论(0)
提交回复
热议问题