Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This page provides syntax for strings and characters in Julia as well as some of their associated functions. Each section includes an example to demonstrate the described syntax or function.
Char
is a single character
String
is a sequence of one or more characters (index values start at 1
)
Action | Function |
---|---|
Use typeof()
function to determine type
Input:
Output:
Julia Documentation: Manual - Strings
Julia Documentation: Base - Strings
Think Julia: Chapter 8 - Strings
get word
length
length(word)
extract nth
character from word
word[n]
extract substring nth-mth
character from word
word[n:m]
search for letter
in word
findfirst(isequal(letter), word)
search for subword
in word
occursin(word, subword)
remove record separator from word
(e.g., n
)
chomp(word)
remove last character from word
chop(word)
Julia is an open source dynamic programming language for high-level, high-performance numerical computing [1]. Julia provides ease and expressiveness (similar to R, MATLAB, and Python), but also supports general programming [2].
Development of Julia began in 2009, and the first version was released in February 2012. The current version of Julia is 1.11 (as of November 2024).
Learn X in Y Minutes: X=Julia
Instructions for installing Julia on macOS and Windows operating systems can be found here.
Package managers such as Homebrew (macOS and Linux) and Chocolatey (Windows) can be used to facilitate installation.
For most users, it is recommended to download the current stable release from https://julialang.org/downloads/.
Some developers might wish to use a different version, or to switch between versions. For this, the Juliaup version manager can be useful.
Julia is also available for use in Brown's Computing Environments:
Oscar (for high-performance computing)
Stronghold (for secure computing)
List of exercises found across the different Julia pages.
Use Julia in Brown Oscar Computing Environment - Forthcoming!
Use Julia in Brown Stronghold Computing Environment - Forthcoming!
Create a Health Calculator Using Julia - Forthcoming!
Create a Pediatric Dosage Calculator Using Julia
Create a BMI Calculator Using Julia
Analyze Health Datasets Using Unix Commands - Forthcoming!
Analyze MIMIC-IV Demo Files Using Unix Commands
Analyze SyntheticRI Demo Files Using Unix
Analyze Health Datasets Using Julia - Forthcoming!
Analyze MIMIC-IV Demo Files Using Julia
Analyze SyntheticRI Demo Files Using Julia
This is the typical first program for those new to a general purpose programming language like Julia. It can be used to test that the Installation of Julia is working and also introduce Julia's basic syntax using the REPL environment or running code written using a Text Editor at the Unix command line.
Input:
Output:
Here are variations of the "Hello, World!" programming using variables and different print statements.
Input:
Output:
In order to assign variables in Julia, you write the desired name for your variable, an =
sign, and what the value of the variable should be.
Input:
Output:
We can write comments on our code, which do not run, to describe what certain lines of code or section of code do
These comments are just for the programmer, they will not appear anywhere in the output and just are there to explain what the code is doing or to provide helpful notes
To make a comment in Julia, you can use the “#” symbol and then type your comment
Sometimes you might want to write longer comments that span multiple lines – to do this you can surround these comments with #=
above the start as well as =#
below the end
Input:
Output:
Without using a print statement, Julia will only print out the most recent item that has an output. In order to print multiple things, we can use the print()
or println()
functions.
Input:
Output:
Use Julia in Brown Oscar Computing Environment - Forthcoming!
Use Julia in Brown Stronghold Computing Environment - Forthcoming!
Julia Documentation: Variables
Julia Documentation: Scope of Variables
Think Julia: Chapter 1 - The Way of the Program
Think Julia: Chapter 2 - Variables, Expressions and Statements
This page provides syntax for using numbers and mathematic operations in Julia. Each section includes an example to demonstrate the described syntax and operations.
Integer (positive and negative counting number) - e.g., -3, -2, -1, 0, 1, 2, and 3
Signed: Int8, Int16, Int32, Int64, and Int128
Unsigned: UInt8, UInt16, UInt32, UInt64, and UInt128
Boolean: Bool
(0 = False and 1 = True)
Float (real or floating point numbers) - e.g., -2.14, 0.0, and 3.777
Float16, Float32, Float64
Use typeof()
function to determine type
Input:
Output:
Input:
Output:
Input:
Output:
Create a Health Calculator Using Julia - Forthcoming!
Julia Documentation: Integers and Floating Point Numbers
Julia Documentation: Mathematical Operations and Elementary Functions
Julia Documentation: Numbers
Julia Documentation: Mathematics
Think Julia: Chapter 1 - The Way of the Program
Julia comes with a full-featured interactive command-line REPL (read-eval-print loop) built into the
julia
executable. In addition to allowing quick and easy evaluation of Julia statements, it has a searchable history, tab-completion, many helpful keybindings, and dedicated help?
and shell modes;
. [1]
This page provides examples of using REPL on the command line.
Type julia
in terminal to launch REPL
Type "?" to enter help pages within REPL
Type a function from Julia to read help pages (ex: println
)
Julia Contributors. (n.d.). REPL - Standard Library - Julia Language. Retrieved May 1, 2024, from https://docs.julialang.org/en/v1/stdlib/REPL/
Julia Documentation: The Julia REPL
Julia Cheat Sheet (see REPL)
Regular expressions (regex) are powerful tools for pattern matching and text processing. They are represented as a pattern that consists of a special set of characters to search for in a string
str
.
This page provides syntax for regular expressions in Julia . Each section includes an example to demonstrate the described methods.
Action | Function |
---|---|
Character class specifies a list of characters to match ([...]
where ...
represents the list) or not match ([^...]
)
Anchors are special characters that can be used to match a pattern at a specified position
Repetition or quantifier characters specify the number of times to match a particular character or set of characters
Input:
Output:
Julia Documentation: Manual - Strings (see Regular Expressions)
Think Julia: Chapter 8 - Strings
In computer programming, a package is a collection of modules or programs that are often published as tools for a range of common use cases, such as text processing and doing math. Programmers can install these packages and take advantage of their functionality within their own code.
This page provides instructions for installing, using, and troubleshooting packages in Julia.
Start Julia REPL by typing the following in Terminal or PowerShell (Note: do not need to type $ - this is to indicate the shell prompt)
Go into REPL mode for Pkg, Julia’s built in package manager, by pressing ]
Update package repository in Pkg REPL
Add packages in Pkg REPL
Check installation
Get back to the Julia REPL and exit by pressing backspace or ^C.
To see REPL history
If you get an error like: ERROR: SystemError: opening file "C:\\Users\\User\\.julia\\registries\\General\\Registry.toml"
: No such file or directory
Delete C:\\Users\\User\\.julia\\registries
where User is your computer’s username and try again
https://discourse.julialang.org/t/registry-toml-missing/24152
Many Julia programs involve the input and output of files. When analyzing a dataset, that dataset file will need to be pulled into your program (input). If you want to see the results of your analysis, your program will need an output.
This section provides the syntax for inputing files (reading) and outputting results (writing) use base Julia (i.e., no packages such as CSV.jl).
Tabulate and report counts for sex in from the .
Dataset (example lines from adult.data
)
Input (process_file.jl
)
Output
Terminal
Analyze the MIMIC-IV Demo Files Using Julia - Forthcoming!
Analyze the SyntheticRI Demo Files Using Julia - Forthcoming!
In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.
This page provides syntax for some of the common control flow methods in Julia . Each section includes an example to demonstrate the described methods.
Test if a specified expression is true or false
Short-circuit evaluation
Test if all of the conditions are true x && y
Test if any of the conditions are true x || y
Test if a condition is not true !z
Conditional evaluation
if
statement
if-else
if-elseif-else
?:
(ternary operator)
Input:
Output:
Repeat a block of code a specified number of times or until some condition is met.
while
loop
for
loop
Use break
to terminate loop
Input:
Output:
Input:
Output:
DataFrames.jl is a Julia package that provides a set of tools for working with tabular data in Julia. Its design and functionality are similar to those of (in Python) and
data.frame
, and (in R), making it a great general purpose data science tool.
This page provides examples of using DataFrames.jl, demonstrating the syntax and common functions within the package.
Install and Load DataFrames.jl Package
Create Dataframe
Display Dataframe
Input:
Output:
First two lines of dataframe:
Input:
Output:
Last two lines of dataframe:
Input:
Output:
Describe Dataframe
Dataframe size:
Input:
Output:
Dataframe column names:
Input:
Output:
Dataframe description:
Input:
Output:
Accessing DataFrames
Get "age" column (different ways to call the column)
Input:
Output:
Get row
Input:
Output:
Get element
Input:
Output:
Get subset (specific rows and all columns)
Input:
Output:
Get subset (all rows and specific columns)
Input:
Output:
Get subset (all rows meeting specified criteria - numbers)
Input:
Output:
Get subset (all rows meeting specified criteria - strings)
Input:
Output:
Get subset (all rows meeting specified criteria)
Input:
Output:
Add Column
New columns with specified values
Input:
Output:
New column with calculated value
Input:
Output:
Get counts/frequency
Input:
Output:
Transform DataFrame
sort
Input:
Output:
stack (reshape from wide to long format)
Input:
Output:
unstack (reshape from long to wide format)
Input:
Output:
Traversing DataFrame (for loops)
sort
Input:
Output:
Analyzing Health Datasets with DataFrames in Julia - Forthcoming!
In computer programming, a collection is a grouping of some variable number of data items (possibly zero) that have some shared significance to the problem being solved and need to be operated upon together in some controlled fashion.
This page provides syntax for different types of collections and data structures in Julia (arrays, sets, dictionaries, etc.). Each section includes an example to demonstrate the described methods.
Arrays are ordered collection of elements. In Julia
they are automatically indexed (consecutively numbered) by an integer starting with 1.
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Input:
Output:
Sets are an unordered collection of unique elements.
Input:
Output:
Dictionaries are unordered collection of key-value pairs where the key serves as the index (“associative collection”). Similar to elements of a set, keys are always unique.
Input:
Output:
Operator | Example |
---|---|
Operator | Example |
---|---|
Anchor | Special Character |
---|---|
Repetition | Character |
---|---|
and organizations (focused on Julia packages for health and life sciences)
Julia Package:
Julia Package:
Julia Documentation:
Think Julia:
Operator | Example |
---|
Wikipedia contributors. (n.d.). Control flow. In Wikipedia. Retrieved May 1, 2024, from
Julia Documentation:
Think Julia:
Think Julia:
JuliaData Contributors. (n.d.). DataFrames.jl - JuliaData. Retrieved May 1, 2024, from
Julia Package:
Julia Package:
Julia Data Science:
Introducing Julia Wikibook:
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Action | Syntax |
---|
Wikipedia contributors (n.d.). Collection. In Wikipedia. Retrieved May 1, 2024, from
Julia Documentation:
Think Julia:
Think Julia:
Think Julia:
Addition
x + y
Subtraction
x - y
Multiplication
x * y
Division
x / y
Power (Exponent)
x ^ y
Remainder (Modulo)
x % y
Negation (for Bool)
!x
Equality
x == y or isequal(x, y)
Inequality
x != y or !isequal (x, y)
Less than
x < y
Less than or equal to
x <= y
Greater than
x > y
Greater than or equal to
x >= y
Check if regex matches a string
occursin(r"pattern", str)
Capture regex matches
match(r"pattern", str)
Specify alternative regex
pattern1|pattern2
Character Class
...
Any lowercase vowel
\[aeiou]
Any digit
[0-9]
Any lowercase letter
[a-z]
Any uppercase letter
[A-Z]
Any digit, lowercase letter, or uppercase letter
[a-zA-Z0-9]
Anything except a lowercase vowel
[^aeiou]
Anything except a digit
[^0-9]
Anything except a space
[^ ]
Any character
.
Any word character (equivalent to [a-zA-Z0-9_]
)
\w
Any non-word character (equivalent to [^a-zA-Z0-9_]
)
W
A digit character (equivalent to [0-9]
)
\d
Any non-digit character (equivalent to [^0-9]
)
\D
Any whitespace character (equivalent to [\t\r\n\f]
)
\s
Any non-whitespace character (equivalent to [^\t\r\n\f]
)
\S
Beginning of line
^
End of line
$
Beginning of string
\A
End of string
\Z
Zero or more times
*
One or more times
+
Zero or one time
?
Exactly n times
{n}
n or more times
{n,}
m or less times
{,m}
At least n and at most m times
{n.m}
Equality | x == y or isequal(x, y) |
Inequality | x != y or !isequal (x, y) |
Less than | x < y |
Less than or equal to | x <= y |
Greater than | x > y |
Greater than or equal to | x >= y |
Add element to end |
|
Remove element from end |
|
Remove element from beginning |
|
Add element to beginning |
|
Sort array (will not change array itself) |
|
Sort array in place (will change array) |
|
Get unique elements in array |
|
Intersection |
|
Union |
|
Convert array to string |
|
New set (empty) |
|
Specify type |
|
Set with values |
|
Set with values |
|
Get length of set my_set |
|
Check if value is in set |
|
Add value |
|
Intersection |
|
Union |
|
Difference |
|
New dictionary (empty) |
|
Specify type |
|
Dictionary with values |
|
Get value for key in dictionary my_dict |
|
Check if dictionary has key |
|
Check for key/value pair |
|
Get value and set default |
|
Add key/value pair |
|
Delete key/value pair |
|
Get keys |
|
Get values |
|
Convert keys to array |
|
Convert values to array |
|
Sorting keys |
|
Sorting values |
|
Sort by value (descending) with keys |
|
Sort by value (ascending) with keys |
|
Get top n by value (e.g., 3) |
|
New array (empty) |
|
Specify type (integer) |
|
Specify type (string) |
|
Array with values |
|
Array with values |
|
Array of numbers |
|
Split string |
|
Get length of array my_array |
|
Get first element of array my_array |
|
Get last element of array my_array |
|
Get n element of array my_array (e.g., 2) |
|
Check if element is in array |
|