Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lei-zhang committed Mar 18, 2019
1 parent d01ad8d commit a34a39c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 84 deletions.
152 changes: 76 additions & 76 deletions 01.R_basics/.Rhistory
Original file line number Diff line number Diff line change
@@ -1,79 +1,3 @@
arr <- array(v1, dim=c(2,2,3))
arr <- array(v1, dim=c(2,2,3))
arr
class(m1)
class(arr)
# dataframe
df <- data.frame(v1=v1, v2=v2, v3=v3, f=f)
class(df)
str(df)
df$v1
class(df$v1)
class(df$v2)
class(df$v3)
class(df$f)
cat('a','b','c')
print('a','b','c')
print(c('a','b','c'))
t =.2
t <= 1/3
cat("t =", , ", t <= 1/3. \n")
cat("t =", t, ", t <= 1/3. \n")
t = .6
cat("t =", t, ", t > 2/3. \n")
cat("t =", t, ", 1/3 < t <= 2/3. \n")
t > 1/3 & t <= 2/3
cat("t =", t, ", 1/3 < t <= 2/3. \n")
cat("t =", t, ", t > 2/3. \n")
t = .0
t = .9
cat("t =", t, ", t > 2/3. \n")
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 1/3 & t <= 2/3) {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
} else {
cat("t =", t, ", t > 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
Expand Down Expand Up @@ -510,3 +434,79 @@ class(df$v2)
class(df$v3)
class(df$f)
install.packages("ggplot2")
month_name <- format(ISOdate(2018,1:12,1),"%B")
month_name
month_name <- format(ISOdate(2019,1:12,1),"%B")
month_name
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
} else if (t > 2/3) {
cat("t =", t, ", t > 2/3. \n")
} else {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", round(t,3), ", t <= 1/3. \n")
} else if (t > 2/3) {
cat("t =", round(t,3), ", t > 2/3. \n")
} else {
cat("t =", round(t,3), ", 1/3 < t <= 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", round(t,3), ", t <= 1/3. \n")
} else if (t > 2/3) {
cat("t =", round(t,3), ", t > 2/3. \n")
} else {
cat("t =", round(t,3), ", 1/3 < t <= 2/3. \n")
}
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", round(t,3), ", t <= 1/3. \n")
} else if (t > 2/3) {
cat("t =", round(t,3), ", t > 2/3. \n")
} else {
cat("t =", round(t,3), ", 1/3 < t <= 2/3. \n")
}
month_name <- format(ISOdate(2018,1:12,1),"%B")
for (j in 1:length(month_name) ) {
cat("The month is", month_name[j], "\n")
}
library(ggplot2)
detach('pachage:ggplot2')
detach('package:ggplot2')
data_dir = ('_data/RL_raw_data/sub01/raw_data_sub01.txt')
data = read.table(data_dir, header = T, sep = ",")
sum(complete.cases(data))
dim(data[complete.cases(data),])
data = data[complete.cases(data),]
data = data[complete.cases(data),]
data[1:10,]
data = data[1:10,]
data
ns = 10
data_dir = '_data/RL_raw_data'
rawdata = c();
for (s in 1:ns) {
sub_file = file.path(data_dir, sprintf('sub%02i/raw_data_sub%02i.txt',s,s))
sub_data = read.table(sub_file, header = T, sep = ",")
rawdata = rbind(rawdata, sub_data)
}
rawdata = rawdata[complete.cases(rawdata),]
rawdata$accuracy = (rawdata$choice == rawdata$correct) * 1.0
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
load('_data/RL_descriptive.RData')
View(descriptive)
descriptive
load('_data/RL_descriptive.RData')
descriptive
descriptive$acc = acc_mean
descriptive
t.test(df$acc, mu = 0.5)
df = descriptive
t.test(df$acc, mu = 0.5)
cor.test(df$IQ, df$acc)
aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
2 changes: 1 addition & 1 deletion 01.R_basics/.Rproj.user/E5E84BA0/console06/INDEX001
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n\n","caption":"Terminal 1","channel_id":"6076","channel_mode":1,"child_procs":false,"cols":103,"cwd":"","exit_code":15,"handle":"A9888C92","interaction_mode":2,"max_output_lines":1000,"restarted":true,"rows":11,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/e/teaching/RL_R_Tromso_2018/R_intro_workshop/01.R_basics","track_env":false,"zombie":false}]
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n\n\n","caption":"Terminal 1","channel_id":"6076","channel_mode":1,"child_procs":false,"cols":103,"cwd":"","exit_code":15,"handle":"A9888C92","interaction_mode":2,"max_output_lines":1000,"restarted":true,"rows":11,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/e/teaching/RL_R_Tromso_2018/R_intro_workshop/01.R_basics","track_env":false,"zombie":false}]
6 changes: 3 additions & 3 deletions 01.R_basics/.Rproj.user/E5E84BA0/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"left" : {
"panelheight" : 638,
"splitterpos" : 175,
"panelheight" : 1118,
"splitterpos" : 631,
"topwindowstate" : "HIDE",
"windowheight" : 676
"windowheight" : 1156
},
"right" : {
"panelheight" : 1118,
Expand Down
8 changes: 7 additions & 1 deletion 01.R_basics/_scripts/R_basics.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class(df$f)
## Control Flow

# if-else
# - generate a random number between 0 and 1
# - compare it against 1/3 and 2/3
# - print this random number and its position relative to 1/3 and 2/3

t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", , ", t <= 1/3. \n")
Expand All @@ -98,7 +102,9 @@ if (t <= 1/3) {
}

# for-loop
month_name <- format(ISOdate(2018,1:12,1),"%B")
# - Get the name of each month
# - Print it one by one
month_name <- format(ISOdate(2019,1:12,1),"%B")
for (j in 1:length(month_name) ) {
cat()
}
Expand Down
6 changes: 3 additions & 3 deletions 01.R_basics/_scripts/R_basics_master.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class(df$f)
# if-else
t <- runif(1) # random number between 0 and 1
if (t <= 1/3) {
cat("t =", t, ", t <= 1/3. \n")
cat("t =", round(t,3), ", t <= 1/3. \n")
} else if (t > 2/3) {
cat("t =", t, ", t > 2/3. \n")
cat("t =", round(t,3), ", t > 2/3. \n")
} else {
cat("t =", t, ", 1/3 < t <= 2/3. \n")
cat("t =", round(t,3), ", 1/3 < t <= 2/3. \n")
}

# for-loop
Expand Down

0 comments on commit a34a39c

Please sign in to comment.