Вывод
Отложено до лучших времен. Особенно язык R хочу изучить таки до конца.
Сейчас все свободное время отдаю фотоделу.
Куча информации, программ обучения, было бы желание и ВРЕМЯ!
Дневник цели
In R, you can construct a matrix with the matrix function, for example: matrix(1:9, byrow=TRUE, nrow=3)
The argument byrow
indicates that the matrix is filled by the rows. If we want the vector to be filled by the columns, we just place bycol=TRUE
or byrow=FALSE
The third argument nrow
indicates that the matrix should have three rows.
rownames(my.matrix) <- row.names.vectors
colnames(my.matrix) <- col.names.vectors
sum.of.rows.vector<- rowSums(my.matrix)
cbind()
, which merges matrices and/or vectors together by column. For example: new.combined.matrix <- cbind( matrix1, matrix2, vector1, ... )
Just like every cbind()
has an rbind()
, every colSums()
has a rowSums()
my.matrix[1,2]
selects from the first row the second element
sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8)) - 100 experiments
Lab 2 - Probability
sbux_df[rows, columns]
ex.:
sbux_df[1:5, "Adj.Close"]
sbux_df[1:5, 2]
sbux_df$Adj.Close[1:5]
The which
function returns the indices for which a condition is TRUE
. For example: which(sbux_df$Date == "3/1/1994")
returns the position of the date 3/1/1994, which indicates in this case the row number in the sbux_df
data frame.
type="l"
specifies a line plot, col="blue"
indicates that line should be blue, lwd=2
doubles the line thickness, ylab="Adjusted close"
adds a y-axis label and main="Monthly closing price of SBUX"
In case you would like to calculate the price difference over time, you can use:sbux_prices_df[2:n,1] - sbux_prices_df[1:(n-1),1]
names(sbux_ccret) = sbux_df[2:n, 1] - named the colomns
cbind
function to paste the two vectors containing both types of returns next to each other in a matrix
ylab="Return"
specifies that "Return"
is the label of the y-axis
cumprod
function that calculates that cumulative product
_____________________________________________________________
sbux_prices_df = sbux_df[, "Adj.Close", drop = FALSE]
# Denote n the number of time periods
n = nrow(sbux_prices_df)
sbux_ret = (sbux_prices_df[2:n,1] - sbux_prices_df[1:(n-1),1])/sbux_prices_df[1:(n-1),1]
___________________________________________________________
cdc[567, 6] - to see the sixth variable (which happens to be weight
) of the 567th respondent
cdc[1:10, 6] - also, alternative cdc$weight[1:10]
subset(cdc, cdc$gender == "m") - will return a data frame that only contains the men from the cdc
data frame.
cdc$gender == "m" and another in the console resul True or False
The &
is read "and" so that subset(cdc, cdc$gender == "f" & cdc$age > 30)
The |
character is read "or" so that subset(cdc, cdc$gender == "f" | cdc$age > 30)
boxplot(cdc$weight)
boxplot(cdc$height ~ cdc$gender) - compare the heights of men and women with
hist(cdc$weight, breaks=50)
will split the data across 50 bins
Lab 1 - Introduction to data
load(url("url_to_your_data_set")) - load data
head, tail
mean
, var
and median
summary
returns a numerical summary: minimum, first quartile, median, mean, third quartile, andmaximum.
table(cdc$smoke100) - to see the number of people who have smoked at least 100 cigarettes in their lifetime
table(cdc$genhlth)/20000 - Ex.: Compute the relative frequency distribution of genhlth
barplot - Ex.: barplot(table(cdc$smoke100)) (hystogram)
read.table("url") - function, read the data
dim(my_data_frame) - will give you the dimensions of your data frame Ex.: 63 3
names(my_data_frame) - Ex.: "year" "boys" "girls"
my_data_frame$variable_name - access the data in a single column of a data frame separately
plot(x, y) - Ex.: simple plot of the number of girls born per year (plot(x = present$year, y = present$girls))
type = "l" - add a third argument (plot(x=present$years, y=present$girls, type="l"))
data_frame$variable_name_1 + data_frame$variable_name_2 + ... - sum. Ex.: babies = present$girls + present$boys
Lab 0 - Introduction to R
Посмотрел все видео на данный момент доступные: Unit 1, Part 2.
Unit 1 Quiz - Introduction in data: 7.56/12. Были совершенно глупые ошибки.
Курс Introduction to R
Chapter 1 - Intro to basics
Chapter 2 - Vectors
numeric_vector <- c(1,2,3)
character_vector <- c("a","b","c")
boolean_vector <- c(TRUE,FALSE)
names(some_vector) - named keys
total_poker <- sum(poker_vector) - find summa
poker_vector[c(1,5)] - select the first amd the fifth day
poker_vector[2:4] - select 2 up to 4
poker_vector[c("Monday","Tuesday")] - select the first element with correct name
mean(vector_name) - average sth
The nice thing about R is that you can use these comparison operators also on vectors. For example, the statement c(4,5,6) > 5
returns: FALSE FALSE TRUE
________________________________________
selection_vector <- poker_vector > 0
# Select from poker_vector these days
poker_winning_days <- poker_vector[selection_vector]
_______________________________________________________________
my_variable <- 4 - присвоение
my_variable - печать
class(some_variable_name) - проверка класса
______________________________________________
довольно забавно, что знак присвоения это не "равно"