# Chapter 4: Data Management

Links to a carefully curated collection of Youtube videos provide a host of additional sourcs for you to develop your ability to use R software in an engaging and accessible manner.

Video 4.1: ‘R tutorial: the basic data types in R’

Question 1: What are the different basic data types in R?

Answer: Logical, numeric, integer (form of numeric), and characters

Question 2: How can you check the data type of a variable in R?

Answer: You can use the class() function, but also you can use the is._() function.

Question 3: How can you coerce one variable type to another type in R?

Answer: You can use the as._() function.

Video 4.2: ‘R tutorial: using the data frame in R’

Question 1: What are the rows and columns in a data frame in R?

Answer: Rows are the observations and columns are the variables.

Question 2: How do we create our own data frame in R?

Answer: You combine your variables using the data.frame() function, where all variables need to be the same length.

Video 4.3: ‘Importing data into R – how to import csv and text files into R’

Question 1: How do we read-in csv files into R?

Answer: You can use the read.csv() function or the read.table() function (but need to specify more arguments).

Question 2: What does the read.csv2() function do?

Answer: It is for csv files that use commas instead of decimals in numbers; which is more common in Europe.

Video 4.4: ‘How to subset data in R with square brackets and logical statements’

Question 1: What is the difference between using = and == in R?

Answer: = can be used to assign values to objects, while == means ‘equal to’ in a mathematical sense.

Question 2: Why is ‘female’ and ‘male’ but in quotes in the R code?

Answer: Because those are the character values for the factor variable ‘gender’ in the dataset.

Question 3: How do we keep all the columns when subsetting the dataset?

Answer: You leave a blank space after the comma in the square brackets.

Video 4.5: ‘How to export data out of R (into .csv, .txt, and other formats)’

Question 1: Why would we want to export data out of R?

Answer: In order to save data that we have manipulated from an existing dataset, we can export as some file format.

Question 2: What happens when we save a file with the same name as an existing file?

Answer: The file is saved, but it automatically overwrites the existing file.

Question 3: What is the quicker way of saving files as csv in R?

Answer: Use the write.csv() function instead of the more generic write.table() function.

Video 4.6: ‘Changing a numeric variable to categorical variable in R’

Question 1: What is the R function used to create the categorical variable?