Last active
March 19, 2024 14:26
-
-
Save mh0w/f7a5912dd59f3a1c044a6fd81048201c to your computer and use it in GitHub Desktop.
R basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Package management: install packages and any dependencies | |
install.packages("rmarkdown", dependencies = TRUE, type = "win.binary") | |
# Load Packages | |
library(ggplot2) | |
library(tidyverse) | |
# Create toy dataframe | |
ab.seq <- as.data.frame(seq(from = 1, to = 100, by = 1)) | |
ab.seq$new_var <- rep(0, times = 100) | |
# Load toy datasets from ggplot2, calling the object dia.dat | |
dia.dat <- diamonds | |
package:ggplot2 | |
# Change column names | |
colnames(ab.seq) | |
# Check column names | |
colnames(ab.seq) <- c("new_var_name_a", "new_var_name_b") | |
# print data to console - cars is a built-in toy dataframe | |
head(ab.seq, n = 2) | |
head(cars) | |
head(cars$dist) | |
print(cars$dist) | |
# print/echo | |
print("hello world") | |
# Plot 'diamonds' dataframe, which comes with the ggplot package | |
ggplot(data = diamonds, | |
mapping = aes(x = price, | |
y = carat, | |
colour = cut)) + | |
geom_point() + | |
labs(title = "Diamond Price, plotted against Carat", | |
x = "Price", | |
y = "Carat") | |
# Basic maths | |
my_data <- c(1, 1, 5, 6, 10, 11, 12, 11, 19) | |
mean(my_data) | |
sd(my_data) | |
max(my_data) | |
min(my_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment