## 4.7 变量变换

function grades_2020()
name = ["Sally", "Bob", "Alice", "Hank"]
grade_2020 = [1, 5, 8.5, 4]
end
grades_2020()
Sally 1.0
Bob 5.0
Alice 8.5
Hank 4.0

plus_one(grades) = grades .+ 1
transform(grades_2020(), :grade_2020 => plus_one)
Sally 1.0 2.0
Bob 5.0 6.0
Alice 8.5 9.5
Hank 4.0 5.0

transform(grades_2020(), :grade_2020 => plus_one => :grade_2020)
Sally 2.0
Bob 6.0
Alice 9.5
Hank 5.0

transform(grades_2020(), :grade_2020 => plus_one; renamecols=false)
Sally 2.0
Bob 6.0
Alice 9.5
Hank 5.0

select(grades_2020(), :, :grade_2020 => plus_one => :grade_2020)
Sally 2.0
Bob 6.0
Alice 9.5
Hank 5.0

df = grades_2020()
df
Sally 2.0
Bob 6.0
Alice 9.5
Hank 5.0

### 4.7.1 多条件变换

leftjoined = leftjoin(grades_2020(), grades_2021(); on=:name)
Sally 1.0 9.5
Hank 4.0 6.0
Bob 5.0 missing
Alice 8.5 missing

pass(A, B) = [5.5 < a || 5.5 < b for (a, b) in zip(A, B)]
transform(leftjoined, [:grade_2020, :grade_2021] => pass; renamecols=false)
Sally 1.0 9.5 true
Hank 4.0 6.0 true
Bob 5.0 missing missing
Alice 8.5 missing true

function only_pass()
only_pass()
["Sally", "Hank", "Alice"]