- Home
- Courses
- R
- Beginner
- Intermediate
- Advanced
- Excel
- Biotech Stocks
- Career
- R
- Blog
- Exercise Database
- Contact
- Home
- Courses
- R
- Beginner
- Intermediate
- Advanced
- Excel
- Biotech Stocks
- Career
- R
- Blog
- Exercise Database
- Contact
Exercise Database
- Home
- Exercise Database
R Exercises – 71-80 – Loops (For Loop, Which Loop, Repeat Loop), If and Ifelse Statements in R
- R Tutorials
- Exercise Database
- for loop, if, if statement, ifelse, ifelse statement, loops, repeat loop, while loop
1. Simple ifelsestatement Create the data frame ‘student.df’ with the data provided below: Use a simple ‘ifelse’ statement to add a new column ‘male.teen’ to the data frame.This is a boolean column, indicating T if the observation is a male younger than 20 years. 2. Double for loop Write a double for loop which prints
Continue Reading…
R Exercises – 61-70 – R String Manipulation | Working with ‘gsub’ and ‘regex’ | Regular Expressions in R
- R Tutorials
- Exercise Database
- gsub, regex, strings
Required packages and datasets 1.‘College’ dataset – Colleges in Texas a.Get familiar with the ‘college’ dataset and its row names. b.Get a vector with the college names (‘college.names’) which you will need in the further steps of this and the next exercises. c.Get a vector (‘texas.college’) which contains all colleges with ‘Texas’ in its name.
Continue Reading…
R Exercises – 51-60 – Data Pre-Processing with Data.Table
- R Tutorials
- Exercise Database
- data management, data pre-processing, exercise database
Required packages for the excises 1.‘College’ dataset – Basic row manipulations a.Transform ‘College’ from ‘ISLR’ to data.table. Make sure to keep the University identifier. We will use this new data.table called ‘dtcollege’ throughout this block of exercises. b.Get familiar with the dataset and its variables. c.Extract rows 40 to 60 as a new data.table (‘mysubset’).
Continue Reading…
R Exercises – 41-50 – Working with Time Series Data
- R Tutorials
- Exercise Database
- exercise, time series
1.Simple time series plot on ‘non-ts’ data a.Get 200 random numbers and call the object ‘mydata’. Let’s set a seed of 14 for reproducibility. b.Get a time series plot without converting to class ‘ts’. c.Add ablines to the chart to indicate the horizontal boundaries of 0 and 1. 2. Working with ‘xts’ a.Get and load
Continue Reading…
R Exercises – 31-40 – Data Frame Manipulations
- R Tutorials
- Exercise Database
- dataframe, dataset, diamonds, exercise, ggplot2, iris, mtcars, r base
1. Working with the ‘mtcars’ dataset a. Get a histogram of the ‘mpg’ values of ‘mtcars’.Which bin contains the most observations? b. Are there more automatic (0) or manual (1) transmission-type cars in the dataset? Hint: ‘mtcars’ has 32 observations. c. Get a scatter plot of ‘hp’ vs ‘weight’. 2. Working with the ‘iris’ dataset
Continue Reading…
R Exercises – 21-30 – The Apply Family of Functions
- R Tutorials
- Exercise Database
- apply, exercise, functions, lapply, mapply, sapply
1. Function ‘apply’on a simple matrix: a.Get the following matrix of 5 rows and call it ‘mymatrix’ b. Get the mean of each row c. Get the mean of each column d. Sort the columns in ascending order 2. Using ‘lapply’ on a data.frame ‘mtcars’ a.Use three ‘apply’ family functions to get the minimum values
Continue Reading…
R Exercises for Beginners – 11-20 – Easy Functions
- R Tutorials
- Blog, Exercise Database, R Blog
- beginner, functions, r exercises
1. a. Write a function “myfun” of x to the power of its index position (x, x^2, x^3, …) b. Test the function with an x of 1:10 c. Enlarge the function “myfun” with a division through the index position (x, x^2 / 2, x^3 /3, …) 2. a. Write a simple moving average
Continue Reading…
R Exercises for Beginners – 1-10
- R Tutorials
- Blog, Exercise Database, R Blog
- r beginner, r exercise
Practicing is a crucial part of learning a new language. Statistical languages like R are no exception of that rule. Many of my students think the same and would love to see more exercises. Therefore, I decided to write an R exercise sheet for beginners and blog it over here. These R exercises are an
Continue Reading…
Famous and Very Useful Pre-Installed Exercise Datasets in R
- R Tutorials
- Blog, Exercise Database, R Blog
- cars, dataset, diamonds, exercise, iris, lynx, mtcars, rivers
As most of you surely know, R has many exercise datasets already installed. That simply means, as soon as you installed R Base, which includes the library ‘datasets’, you have ample opportunity to explore R with real world data frames. For me as course content creator those datasets help tremendously, because with them I can
Continue Reading…