> set.seed(1)
> x=as.scidb(rnorm(10))
> x[]
# [1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684
# [7] 0.4874291 0.7383247 0.5757814 -0.3053884
> (x < 0)[]
# [1] TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE
> (x#sparse vector (nnz/length = 4/10) of class "dsparseVector"
# [1] -0.6264538 . -0.8356286 . . -0.8204684
# [7] . . . -0.3053884
#> Filter("val < 0", x)[]
#sparse vector (nnz/length = 4/10) of class "dsparseVector"
# [1] -0.6264538 . -0.8356286 . . -0.8204684
# [7] . . . -0.3053884
# Sparse filtered output is useful to use to index SciDB arrays. The next
# example selects just the entries of the array that meet the condition:
> x[x# [1] -0.6264538 -0.8356286 -0.8204684 -0.3053884
# The TRUE/FALSE output array is useful to aggregate by groups defined
# by the condition. The next example computes the mean of the entries
# that are less than zero, and the mean of the entries that are greater
# than or equal to zero:
> aggregate(x, by=(x<0), FUN=mean)[]
# condition_index val_avg condition
#0 0 0.6516612 false
#1 1 -0.6469848 trueRun the code above in your browser using DataLab