Skip to content

Course Notes

Use this workspace to take notes, store code snippets, or build your own interactive cheatsheet! For courses that use data, the datasets will be available in the datasets folder.

# Import any packages you want to use here

Take Notes

Add notes here about the concepts you've learned and code cells with code you want to keep.

Add your notes here

# Add your code snippets here
# Hier steht ein Kommentar
# Vekor is progression of elements of the same data type
some_vector <- c("John Doe", "poker player", "male", "USA")
names(some_vector) <- c("Name", "Profession", "Sex", "Origin")
name <- some_vector[1]
name2 <- some_vector[c(1,3)]
name3 <- some_vector[1:3]
name4 <- some_vector["Name"]
name5 <- some_vector[c("Name", "Profession")]
name6 <- some_vector[c(TRUE,FALSE,FALSE,TRUE)]

print(some_vector)
# Summe ausm Vektor sum()
print(sum(c(1, 2, 3, 4, 5)))
# Durchschnitt ausm Vektor mean()
print(mean(c(1, 2, 3, 4, 6)))
print(name6)
#cbind(matrix,vector/matrix) erweitert Matrix um Spalte
#rbind(matrix,vecotr/matrix) erweitert Matrix um Zeile
#Matrix is collection of elements of the same data type
bsp_mat <- matrix(1:9, byrow = TRUE, nrow = 3, dimnames = c("Title,region"))
#byrow sagt aus dass die Matrix zeilenweise geschrieben wird, bei FALSE wird spaltenweise geschrieben.
colnames(bsp_mat) <- c("S1","S2","S3")
rownames(bsp_mat) <- c("R1","R2","R3")

print(bsp_mat)

zeilensum <- rowSums(bsp_mat) #colSums

print(zeilensum)

mymatrix[1,2]
mymatrix[,1]

#factor(temperature_vector, order = TRUE, levels = c("Low", "Medium", "High"))
#levels(factor_survey_vector) <- c("Female","Male")
#summary(factor_survey_vector)
#factor(speed_vector, ordered = TRUE, levels = c("slow", "medium", "fast"))
#data.frame
#head(mtcars) give the first 6 observations of the df
#tail(mtcars) give the last 6 observations of the df

#str(mtcars) give information about the structure of the df

#data.frame(col1,col2,col3,...)
#my_df[1,2]
#planets_df$diameter Shortcut to get the entire column of the data.frame planets_df
#planets_df[rings_vector, "name"], der rings_vector sagt aus ob Planet Ring hat oder nicht, durch diese Schreibweise bekommt man genau die Planeten, die einen Ring haben
#subset(planets_df, subset = diameter < 1) ist im prinzip das selbe wie planets_df[diameter < 1,]
#a <- c(100, 10, 1000)
#order(a)
#[1] 2 1 3

Vectors (one dimensional array): can hold numeric, character or logical values. The elements in a vector all have the same data type.// Matrices (two dimensional array): can hold numeric, character or logical values. The elements in a matrix all have the same data type.// Data frames (two-dimensional objects): can hold numeric, character or logical values. Within a column all elements have the same data type, but different columns can be of different data type.

A list in R allows you to gather a variety of objects under one name (that is, the name of the list) in an ordered way. These objects can be matrices, vectors, data frames, even other lists, etc. It is not even required that these objects are related to each other in any way.

You could say that a list is some kind super data type: you can store practically any piece of information in it!

#list()
#my_list <- list(name1 = your_comp1, 
#                name2 = your_comp2)
#names() nutzen um nachträglich ein Listenteil zu benennen :)

#shining_list[[1]]
#shining_list[["reviews"]]
#shining_list$reviews