

Here are some useful functions for characterizing a dataframe: head(surveys) # Top of dataframe We can run the name of the variable to view the dataframe, but often there will be too much information to display in the console
DOWNLOAD R STUDIO FOR MAC UF CODE
Note: this code requires having a data/ folder in your project Functions for characterizing dataframe Surveys <- read.csv('data/portal_data_joined.csv')
DOWNLOAD R STUDIO FOR MAC UF DOWNLOAD
We often store our data in comma seperated value (CSV) files, which can be read into R using the read.csv() function: # Download example. Using | can get tedious, instead use %in% to test if any elements in a search vector are present pets <- c("dog", "cat", "mouse") One common task is searching for certain values or string: animals <- c("bear", "tiger", "dog", "cat", "lion")Īnimals Notice that we use = when subsetting instead of =, which is an assigning operatorĪ = 4 can be read as a is equal to 4 Searching for elements We can subset on multiple conditions using & for AND conditions (ie both are TRUE), and | for OR conditions (ie either are TRUE): weight_g Weight_g # Returns vector of only TRUE elements We can assign values to objects using the assignment operator, and use R to do useful things: weight_kg, with TRUE/FALSE to subset only TRUE values: weight_g > 50 # Returns vector of TRUE/FALSE Look at the Cheatsheets in the Help tab in RStudio Creating objects/variables Use args() function to get the arguments for a function Use ? to get the help file for a function
