List comprehension in R

前端 未结 7 1547
执笔经年
执笔经年 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:11

    And, (kind of) the for-comprehension of scala:

    for(i in {x <- 1:100;x[x%%2 == 0]})print(i)
    

提交回复
热议问题