#################################################################################### #This is a file with executable R code for chapter 2 of Natalia Levshina's (2015) #How to Do Linguistics with R. Amsterdam/Philadelphia: John Benjamins. #################################################################################### ###Section 2.2 ##Main text install.packages("cluster") library(cluster) library(Rling) #should be installed first. See the directions in the readme file. data(ldt) ##Boxes with additional information citation() citation("cluster") ###Section 2.3 ##Main text 2 + 2 month.name 2+2;4+4 a <- 3 a a + 5 a = 3 a b <- 7 a + b a + B ls() rm(b) rm(list = ls()) # do not run, unless you want to remove all objects q() getwd() load("C:/Users/YourName/YourDirectory/yourFile.RData") help(cor) ?cor help.search("correlation") ??correlation ##Boxes with additional information -10 + (56 + 76)/12 + 3^4 - 16^(1/2) + 200*0.01 16^(1/4)*(12 + 68)/(211 + 9) a = 3 a == 3 a == 10 ###Section 2.4 ##Main text vnum <- 1:5 vnum fibonacci10 <- c(1, 1, 2, 3, 5, 8, 13, 21, 34, 55) fibonacci10 stein <- c("a", "rose", "is", "a", "rose", "is", "a", "rose") stein stein.fac <- factor(stein) stein.fac table(stein.fac) m <- cbind(1:5, 10:6) m sex <- c("f", "m", "m", "f") sex rt <- c(455, 773, 512, 667) rt df <- data.frame(sex, rt) df str(df) df$sex is(m) ###Section 2.6 data_tab <- read.table("C:/Your/Directory/Example_data_tab.txt", header = TRUE) # you should specify your own path and file name! head(data_tab) str(data_tab) write.table(data_tab, file = "C:/Your/Directory/Exported.txt", quote = FALSE, sep = "\t", row.names = FALSE) # you should specify your own path and file name! png("C:/My/Directory/myplot.png") # you should specify your own path and file name! plot(1:5, 11:15) dev.off()