### ----------------------------------------------------------------------- ### Programmieren mit statistischer Software (SoSe 2017) ### ----------------------------------------------------------------------- ## ----eval1--------------------------------------------------------------- 1+1 ## ----object1------------------------------------------------------------- a <- 1+1 a ## ----object2------------------------------------------------------------- b<-"Hello World" b ## ----object3------------------------------------------------------------- ls() objects() ## ----object4------------------------------------------------------------- rm(a) a ls() ## ----object5------------------------------------------------------------- rm(list=ls()) ## ----pfad1--------------------------------------------------------------- setwd("Laufwerk:/Pfad") setwd("S:/ProgStat") setwd("S:\\ProgStat") # setwd("S:\ProgStat") funktioniert nicht ## ----pfad2--------------------------------------------------------------- getwd() ## ----speichernladen1----------------------------------------------------- save.image() load(".RData") ## ----speichern----------------------------------------------------------- save() ## ----speichernladen2----------------------------------------------------- x <- 1:10 save(x, file="./Ergebnisse/jargon.RData") load("./Ergebnisse/jargon.RData") ## ----speichernladen3----------------------------------------------------- setwd("./Ergebnisse") save(x, file="../jargon.RData") load("../jargon.RData") ## ----help1--------------------------------------------------------------- help(ls) ?ls ## ----help2--------------------------------------------------------------- ?"if" # ?if funktioniert nicht ?"while" ## ----help3--------------------------------------------------------------- example("ls") ## ----help4--------------------------------------------------------------- help.search("linear models") help.search("nonparametric") ??"subset" ## ----lang1--------------------------------------------------------------- x <-1 x X <-"a" X ## ----lang2--------------------------------------------------------------- identity(1:10) ## ----lang3--------------------------------------------------------------- identity table ## ----lang4--------------------------------------------------------------- 1 + 1 -1 2*4 12/4 '+'(1,1) ## ----lang5--------------------------------------------------------------- x <- 4.2 is.vector(x) length(x) ## ----lang6--------------------------------------------------------------- x <- c(4.2, 13, 5) cos(x) sin(x) x+1 ## ----lang7--------------------------------------------------------------- matrix(c(1,0,0,1), nrow=2, ncol=2) # analog diag(2) ## ----lang8--------------------------------------------------------------- diag(2) + diag(2) ## ----lang9--------------------------------------------------------------- 2*diag(2)*diag(2) ## ----lang10-------------------------------------------------------------- (diag(2)*2) %*% (diag(2)*4) ## ----com----------------------------------------------------------------- 1+1 # 2+2 ## ----pack1--------------------------------------------------------------- library() ## ----pack2--------------------------------------------------------------- search() ## ----pack3--------------------------------------------------------------- library("tools") require("sos") ## ----pack4--------------------------------------------------------------- detach("package:tools") ## ----pack5--------------------------------------------------------------- install.packages("archetypes") ## ----pack6--------------------------------------------------------------- update.packages() ## ----pack7--------------------------------------------------------------- download.packages() ## ----pack8--------------------------------------------------------------- getOption("repos") ## ----pack9--------------------------------------------------------------- .libPaths() ## ----pack10-------------------------------------------------------------- library(help = "graphics") library(help = "archetypes") ## ----pack11-------------------------------------------------------------- data(package = "archetypes") data("body", package = "archetypes") body ## ----pack12-------------------------------------------------------------- demo(package = "archetypes") demo("robust-ozone", package = "archetypes") ## ----pack13-------------------------------------------------------------- edit(file = system.file("demo", "robust-ozone.R", package = "archetypes")) ## ----pack14-------------------------------------------------------------- vignette(package = "archetypes") vignette("archetypes", package = "archetypes") # Folgendes funktioniert in R, aber nicht in RStudio edit(vignette("archetypes", package = "archetypes")) # so funktioniert es in RStudio edit(vignette("archetypes", package = "archetypes"), editor="internal") # so funktioniert es in RStudio ## ----script1------------------------------------------------------------- a <- 2:8 b <- pi c <- a * b save(c, file = "res.RData") load("res.RData") ## ----script2------------------------------------------------------------- source("basic-1.R")