# Addition (this is a comment: preceded by '#')
5 + 5
[1] 10
# Multiplication
5 * 3
[1] 15
# Division
5 / 3
[1] 1.6667
'data.frame': 19 obs. of 4 variables:
$ Participant : chr "VENI-NL_1" "VENI-NL_10" "VENI-NL_11" "VENI-NL_12" ...
$ Sex : chr "M" "M" "M" "M" ...
$ Frontness.T : num 0.781 0.766 0.884 0.748 0.748 ...
$ Frontness.TH: num 0.738 0.767 0.879 0.761 0.774 ...
head
Participant Sex Frontness.T Frontness.TH
1 VENI-NL_1 M 0.78052 0.73801
Sex Frontness.T
1 M 0.78052
2 M 0.76621
[1] "VENI-NL_1" "VENI-NL_10" "VENI-NL_11"
tmp <- dat[dat$Sex == 'M',] # only observations for male participants
head(tmp, n=2) # show first two rows
Participant Sex Frontness.T Frontness.TH
1 VENI-NL_1 M 0.78052 0.73801
2 VENI-NL_10 M 0.76621 0.76685
# more advanced subsetting: include rows for which frontness
# for the T sound is higher than 0.74 AND participant is either 1 or 2
# N.B. use "|" instead of "&" for logical OR
dat[dat$Frontness.T > 0.74 & dat$Participant %in% c('VENI-NL_1','VENI-NL_2'),]
Participant Sex Frontness.T Frontness.TH
1 VENI-NL_1 M 0.78052 0.73801
# new column Diff containing difference between TH and T positions
dat$Diff <- dat$Frontness.TH - dat$Frontness.T
# new column DiffClass, initially all observations set to TH0
dat$DiffClass <- 'TH0'
# observations with Diff larger than 0.02 are categorized as TH1, negative as TH-
dat[dat$Diff > 0.02,]$DiffClass <- 'TH1'
dat[dat$Diff < 0,]$DiffClass <- 'TH-'
dat$DiffClass <- factor(dat$DiffClass) # convert string variable to factor
head(dat,2)
Participant Sex Frontness.T Frontness.TH Diff DiffClass
1 VENI-NL_1 M 0.78052 0.73801 -0.04250668 TH-
2 VENI-NL_10 M 0.76621 0.76685 0.00064245 TH0
swirl()
and finish the following lessons of the R Programming course:
[1] 0.038213
[1] 0.0014603
0% 25% 50% 75% 100%
-0.0425067 -0.0038419 0.0109299 0.0248903 0.1034607
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.04251 -0.00384 0.01093 0.01626 0.02489 0.10346
[1] 0.71054
# crosstable: relation between two categorical variables
table(dat$Sex, dat$DiffClass) # or: with(dat, table(Sex,DiffClass))
TH- TH0 TH1
F 1 3 5
M 5 4 1
# means per category: relation between numerical and categorical variable
c( mean(dat[dat$Sex=='M',]$Diff), mean(dat[dat$Sex=='F',]$Diff) )
[1] -0.0034299 0.0381446
R
boxplot()
for a boxplothist()
for a histogramqqnorm()
and qqline()
for a quantile-quantile plotplot()
for many types of plots (scatter, line, etc.)barplot()
for a barplot (plotting frequencies)swirl()
and finish the following lesson of the R Programming course:
R
R
for:
install_from_swirl(‘Exploratory_Data_Analysis’)
Thank you for your attention!
https://www.martijnwieling.nl
m.b.wieling@rug.nl