Intro to Computational Studies in Education and the Social Sciences
School of Education
Center for Applied Data Science and Analytics
Posit Cloud is a web-based platform that allows users to perform data science tasks directly in their browser. It provides a cloud-based environment similar to the traditional RStudio integrated development environment (IDE), eliminating the need for local software installation and maintenance. Users can create projects, share work with collaborators, and access features like interactive notebooks. Posit Cloud offers various plans, including a free option for casual use and premium plans for professionals, instructors, and organizations.
You can access the Posit Cloud here.
Directories help us organizer our R projects efficiently.
A common structure includes a root directory that helps set the working directory automatically. Within this root, subdirectories such as “Data” for storing datasets, “src” or “R” for R scripts and functions, “output” for results, and “plots” for visualizations are typically used. This organization enhances project management, improves collaboration, and simplifies file referencing. Using relative file paths allows for more portable code, making it easier to share projects across different computers or with collaborators.
To see your current working directory, we’ll run the getwd() command.
To view files in your working directory, we’ll run the list.files() command.
To create a new directory, we’ll run the dir.create() command.
To set your working directory, we’ll run the setwd() command.
When you set a new working directory, you want to verify the change by using getwd().
Packages in R are collections of functions, data, and documentation that extend the language’s capabilities. They allow users to easily share and reuse code, making R a powerful and flexible tool for data analysis and visualization.
Packages can be installed from repositories like CRAN, and once installed, they can be loaded into an R session to access their functionality. The tidyverse, for example, is a popular collection of packages that provides a consistent and user-friendly approach to data manipulation and visualization.
The downloaded binary packages are in
/var/folders/t2/v2ypghs120z45678ty2nqfk00000gn/T//Rtmp2fxt6e/downloaded_packages
We will learn how to calculate values in R.
Explore different object types
For this task, we will explore three object types: numeric, character, and logic values.
We can assign a variable to this statement by using an assignment operator: <-
We can also use an equal sign to assign values: \(=\)
Type “a” to show the value of the variable
Create a numeric variable “b” that is the product of “a” and “5”
Type “b” in your console to show the product of the two variables
Divide b by 4
Take the square root of b
Compute the natural log of b
Compute the common log of b
Find 1 minus the square root of b
Attempt to find the square root of “1 minus the square root of b” - which is a negative value
NaN stands for “Not a number”. This occurs because there is currently no defined value to recognize the square root of negative numbers in R. But we can compute the square root on the absolute value of this difference, if needed.
We can insert longer or more complex mathematical statements too. For example, we can find the absolute value of the sum of -1 and the square root of b cubed and then subtract from that the value of 3 times the square root of b.
Notice the use of parentheses.
We can override the original value of y to match the mathematical statement we generated above.
We consider all of the previous objects to be numeric.
We can also create objects to hold non-numeric values.
There are two types of non-numeric values: character values and logic values.
We can create a character value using the ‘,’ or “,” quotes.
Logic values can either be TRUE or FALSE
We can also use T for TRUE and F for FALSE.
We will learn to give a variable (or character) a value.
Use the different assignment operators
Set x equal to two added to three
Set y equal to two minus three
Set z equal to two times three
Overwrite the value of y by setting y equal to x divided by z