## Julia Community 🟣

Vinod V

Posted on • Updated on

# Filtering Data Made Easy: Tips and Tricks in Julia

``````data_list = [1, 4, -5, 11, -7, 4, 3, -1]
``````

### Values greater than zero

``````positives = [n for n in data_list if n > 0]
#positives = filter(>(0),data_list)
println(positives)
``````

### Values less than zero

``````negatives = [n for n in data_list if n < 0]
#negatives = filter(<(0),data_list)
println(negatives)
``````

### Negative values replaced with 0

``````neg_to_zero = [n > 0 ? n : 0 for n in data_list]
println(neg_to_zero)
``````

### Positive values replaced with 0

``````pos_to_zero = [n < 0 ? n : 0 for n in data_list]
println(pos_to_zero)
``````

### Filter to a range

``````rang = filter(x-> -3<x<1, data_list) #between -3 and 1
println(rang)
``````

### Clamp between low and high values

``````clamp.(data_list,-2,4)
8-element Vector{Int64}:
1
4
-2
4
-2
4
3
-1
``````

### Select values from a list based on values on some other list

``````addresses = [
"5412 N Alappuzha",
"5148 N Munnar",
"5800 E Kovalam",
"1060 W Kumarakom",
"4801 N Murukani",
"1039 W Kollengode",
]

counts = [0, 3, 10, 4, 1, 7, 6, 1]

more5 = [n > 5 for n in counts]