Using packages

Introduction to Julia

James Fulton

Climate informatics researcher

Packages

  • A collection of Julia files from which you can import
  • Popular packages include
    • Statistics.jl - calculating descriptive statistics
    • DataFrames.jl - storing and manipulating tabular data
    • CSV.jl - loading and saving CSV data
    • Plots.jl - creating visualizations
  • Thousands more packages exist
  • Some lists of packages found here:
Introduction to Julia

Installing packages

import MyPackage
 | Package MyPackage not found, but a package named MyPackage is available from a registry. 
 | Install package?
 |   (@v1.7) pkg> add MyPackage 
 |_ (y/n) [y]:
Introduction to Julia

Importing packages

import Statistics


m = Statistics.mean([1,2,3]) println(m)
2.0
m = mean([1,2,3])
println(m)
ERROR: UndefVarError: mean not defined
using Statistics


m = Statistics.mean([1,2,3]) println(m)
2.0
m = mean([1,2,3])
println(m)
2.0
Introduction to Julia

Importing packages

import Statistics as sts


m = sts.mean([1,2,3]) println(m)
2.0
using Statistics


m = Statistics.mean([1,2,3]) println(m)
2.0
m = mean([1,2,3])
println(m)
2.0
Introduction to Julia

The Statistics package

  • mean() - Calculate mean of array
  • median() - Calculate median value of array
  • std() - Calculate standard deviation of array values
  • var() - Calculate variance of array values
mean_x = Statistics.mean(x_arr)

median_x = Statistics.median(x_arr)

std_x = Statistics.std(x_arr)

var_x = Statistics.var(x_arr)
Introduction to Julia

Let's practice!

Introduction to Julia

Preparing Video For Download...