x <- 1 #Preference: primary method
x = 1 #Preference: within functions
1 -> x #Preference: never
ls()
Cheburashka <- "a cartoon character"
Cheburashka
cheburashka
orig.folder<-getwd()
orig.folder
dir.create("new.folder")
list.files()
setwd("new.folder"); list.files()
setwd(orig.folder)
file.remove("new.folder"); list.files()
install.packages("igraph")
library(igraph)
detach("package:igraph", unload=TRUE)
x <- NA
NA #Non-applicable, missing
NULL #Undefined or empty value
NaN #Not a Number
Inf #Infinite
is.na(x)
is.null(x)
is.nan(x)
is.infinite(x)
is.numeric(42)
is.numeric("42")
is.numeric(3.12)
is.logical(T)
is.logical(FALSE)
is.character(FALSE)
is.character("42")
is.character("HSE Network Workshop")
as.numeric("42") + 1
as.character(as.numeric("0") + 1)
as.character(!as.logical("1"))
as.character(as.logical(as.numeric("0") + 1))
as.character(is.logical(as.logical(as.numeric("0")) + 1))
as.character(!as.logical(as.numeric("1")))
RU.cit<-c("Mos", "StP", "Nov", "Yek") #Create vector RU.cit<-c(RU.cit, "Niz") #Add element RU.cit[3] #Retrieve element 3
RU.pops<-c(10.4, 4.6, 1.4, 1.3) #Create vector names(RU.pops)<-RU.cit[c(1,2,3,4)] #Name vector RU.pops[c(4,2,3,1)] #Permute the order and retrieve length(RU.pops) #Retrieve the length
RU.vis<-c(TRUE, TRUE, FALSE, FALSE) #Create vector RU.vis[-c(4,2)] #Remove elements 4 and 2
all(1:5 == c(1, 2, 3, 4, 5))
all(1:5 == seq(from=1, to=5, by=1))
print(rep(1, times=5))
print(rep(NA, times=4))
print(rep("Beetlejuice", times=3))
RU.mat<-cbind(pop=RU.pops, vis=RU.vis)
rownames(RU.mat)<-RU.cit[c(1:4)]
colnames(RU.mat)
RU.mat<-matrix(,nrow=length(RU.pops), ncol=2)
colnames(RU.mat) <- c("pop", "vis")
rownames(RU.mat) <- names(RU.pops)
RU.mat[,"pop"] <- RU.pops
RU.mat[,"vis"] <- RU.vis
print(RU.mat[1,])
print(RU.mat[,"pop"])
print(RU.mat[1,2])
print(RU.mat[1,,]) #What does the error mean?
print(RU.mat[,"vis"])
print(RU.vis)
RU.df<-as.data.frame(RU.mat)
RU.df$vis<-as.logical(RU.df$vis)
print(RU.df$vis[2])
print(RU.df[2,"vis"])
print(RU.df[["vis"]][2])
print(RU.df[[2]][2])
RU.list<-list(RU.mat, RU.vis, RU.df)
names(RU.list)<-c("Mat","Vec","DF")
print(RU.list$DF$vis[2])
print(RU.list[["DF"]]$vis[2])
print(RU.list[[3]]$vis[2])
print(RU.list[["DF"]][["vis"]][2])
print(RU.list[["DF"]][2,"vis"])
print(RU.list[["DF"]][2,2])
xTimesxMinus1<-function(x) return(x*(x-1))
xTimesxMinus1(42)
InvHypSineTrans<-function(x){
x.ret<-log(x+sqrt(x^2 + 1)) return(x.ret)}
plot(x=1:1000, InvHypSineTrans(1:1000), main="Hyperbolic Sine Transformation", xlab="x", ylab="y")
library(compiler)
InvHypSineTrans.cmp<-cmpfun(InvHypSineTrans)
system.time(InvHypSineTrans(1:10000000))
system.time(InvHypSineTrans.cmp(1:10000000))
??"Chi Squared"
help.search("Chi Squared")
?chisq.test
print(chisq.test)
lab.seq<-seq(from=-100,to=100,by=20)
?sapply
lab.mat<-sapply(lab.seq, rnorm, n=100)
fix(lab.mat)
?apply
lab.means<-apply(lab.mat, 2, mean)
plot(x=lab.seq, y=lab.means)
test.val<-"It works!"
test.val2<-paste(test.val, "Really")
source("test.val.source.txt")
ls()
print(test.val); print(test.val2)
savehistory("Filename.RHistory")
loadhistory("Filename.RHistory")
save.image("Filename.RData")
load("Filename.RData")