DataFrames
Example
Installing data.frame, data.table, and dplyr in R.
Create DataFrame
#Create DataFrame
df <- data.frame(
id = 1:5,
gender = c("F", "M", "F", "M", "F"),
age = c(68, 54, 49, 28, 36)
)Display DataFrame
Describe DataFrame
Accessing DataFrames
Get "age" column (different ways to call the column)
Get row
Get element
Get subset (specific rows and all columns)
Get subset (all rows and specific columns)
Get subset (all rows meeting specified criteria - numbers)
Get subset (all rows meeting specified criteria - strings)
Get subset (all rows meeting specified criteria)
Add Column
New columns with specified values
New column with calculated value
Get counts/frequency
Transform DataFrame
sort
stack (reshape from wide to long format)
unstack (reshape from long to wide format)
Traversing DataFrame (for loops)
sort
Notes:
Resources
Last updated
