Exercises for the Scientific computing using Julia language course
Managing a project environment and packages
For these exercises I am also expecting that you are working in the REPL.
Activating a project environment and installing packages into it
- Activate a project environment in a new folder.
- Install the Dates package from the Julia Ecosystem into your project environment.
- Which files were created when you made the project environment?
- What do each of these files contain?
- How can you see in the REPL that you are in a project environment?
- What is the name of your project environment?
- Change the name of your project environment to something of your choosing.
- Install the DateFrames package?
- How did the project environment files change?
- Find 3 packages that the DataFrames package depends on.
- Find the dependency of DataFrames with the most dependencies
- Install the develop_speed branch of the LocalAncestry package from Github (https://github.com/BgroveP/LocalAncestry.jl/tree/develop_speed)
- Exit the current project environment and access the global environment without exiting Julia
- Reenter your project environment and remove the LocalAncestry package.
- In another folder, prepare a project environment using the instantiate function.
- Write how you would delete your project environment.
Standard types
Integers
- Initialize an integer without explicitly stating its type, e.g. with x = 1. What is its exact type?
- Initialize a decimal number using x = 1.6, and convert the number to its nearest integer.
- Initialize a string using x = “1” and convert it to an integer.
- When multiplying an integer with a float type, does the order of the two matter for the type of the result?
Decimal numbers
- Initialize a decimal number without explicitly stating its type, e.g. with x = 1.0. What is its exact type?
- Convert an integer variable to a float variable
- Convert at string variable to a float variable
Characters
- Initialize an uppercase character
- Initialize a range of characters
- Convert a digit character to an Integer
Strings
- Initialize a variable with the following String value: ABCDEFGhijklmno
- Remove all lowercase letters.
- Retain the third to seventh letter.
- Concatenate the string with this string: pqrstuvwxyz
- Split the string into a vector of individual characters.
- Concatenate each of these characters with a comma suffix.
- Join the vector of strings into one string.
- Replace all commas with empty strings.
- Check if the following string TGGCATCGTAAGCTAGGCATT contains GTAAC.
- Find the position of GTAA in the string above.
- Using regular expressions, remove everything after GTAA in the string above.
Collections
Tuples (Technically not a collection in Julia)
- Create a Tuple object with an integer and a string.
- Unpack this tuple into two separated variables.
- Create a NamedTuple object with an integer and a string.
- Access the values of this named tuple using both their names and indices.
- Can you change one entry in a tuple without remaking the whole object?
Arrays
- Create an 10x1 Array filled with zeros of the Integer type.
- Change the third element to a 3.
- Create a 100 x 10 Array filled with random decimal values. Get the average of each column.
- Create the following Array: [1,5,1,8,3,3,6,7,8,9,2,1,7,0,3,7,5,2,7,1], and remove all values smaller than 6 from it.
Dictionaries
- Create a dictionary object that maps A to 1 and T to 2.
- In a separate line, add the C to 3 mapping.
- Check if the dictionary has an entrance with the C key.
- Delete the entrance with the T key.
- Substract Arrays with the keys and values of the dictionary.
- How would you request a value from a dictionary with a default value when a key is not present?
- Is the order of keys in the dictionary the same as the order in which you entered them?
Functions
- Create a function that calculates the cumulative sum of a vector and returns the result.
- Add an optional logical parameter where if this is true print every second element in the resulting vector.
- Limit the function to only accepting integers.
- Create another function that does the above with a matrix.
- What is the benefit of broadcasting?
General use
CSV package
- Install and load the RDatasets, CSV, and DataFrames packages
- Load the iris dataset from the RDatasets package
- Calculate the average sepal length per species
- Create a lineplot between petal length and petal width where the lines dont cross
- Write all rows except those that contain the setosa species to a .csv file.
- If you have more time, play around with the stack, unstack, joins, transform functions.