getwd()
3 + 4*2
3+3
3 + 4*2
3 + 4*2
sqrt(11)
abs(-2.3)
exp(10)
ceiling(2.3)
floor(2.3)
round(2.3)
round(2.51)
# simple calculations
3 + 4*2
simple calculations
3 + 4*2
a <- 2*3
b <- 7
a*b
a-10
myfunction1 <- function(x){
sqrt(x)+10
}
myfunction1(7)
myfunction1(-2)
myfunction1(2)
x <- 2
myfunction1 <- function(x){
sqrt(x)+10
}
myfunction1(7)
myfunction1(x)
getwd()
setwd('..')
getwd()
setwd('2021_2_online')
getwd()
x <- 2
a*b
a-10
x <- 2
# Help files
?sqrt
?t.test
?ttest
??ttest
??square
??Median
# Packages
library()
search()
library(psych)
# Vectors
x <- c(1,2,5,7)
y <- c(1, 2, "Text", 3)
z <- 3:20
a1 <- 2:-5
a2 <- seq(1:10, by=.1)
a2 <- seq(1, 10, by=.1)
rep(3,4)
rep(c(1,2,3), 2)
rep(c(1,2,3), each=2)
c(1,2,3,4) + 2
c(1,2,3,4) - c(0,2,0,4)
a1 - a
round(a2)
length(a2)
mean(x)
sum(x)
gender <- rep(c(1,2), 10)
gender
gender.f <- factor(gender, labels = c("male", "female"))
table(gender)
table(gender.f)
gender.o <- factor(gender.f, levels=c("female", "male"))
table(gender.o)
intervention <- rep(c("medium", "low", "low", "high", "high", "high"), 5)
intervention
table(intervention)
intervention.f <- factor(intervention)
intervention.o <- factor(intervention.f, levels=c("low", "medium", "high"))
table(intervention.o)
# Indexing
a2[10]
a2
a2[51:60]
a3 <- a2[51:60]
a2[c(1,10,12)]
a2[-10]
a2[-c(10,12,15)]
data1 <- data.frame(gender, gender.o)
View(data1)
data2 <- read.table("blood_pressure.csv", sep=",", header=T)
data2 <- read.table("Data/blood_pressure.csv", sep=",", header=T)
setwd("Data")
data2 <- read.table("blood_pressure.csv", sep=",", header=T)
data3 <- read.xlsx("blood_pressure.xlsx")
library(openxlsx)
data3 <- read.xlsx("blood_pressure.xlsx")
data2 <- read.table("blood_pressure.csv", sep=";", header=T)
View(data2)
data2 <- read.table("blood_pressure.csv", sep=",", header=F)
View(data2)
data2 <- read.table("blood_pressure.csv", sep=",", header=T)
View(data2)
head(data2)
tail(data2)
str(data2)
names(data2)
data2[3,2]
View(data2)
data2[,2]
data2[[2]]
data2$onemonth
data2[3,]
subset(data1, gender.o == "female")
data1.female <- subset(data1, gender.o == "female")
# rename variable
names(data1)[1] <- "ID"
# delete columns
data4 <- data2[,-c(2,3)]
# calculate new variable
data4$sum14 <- data4$before + data4$twelvemonth
# Creating categories
data3$Group <- (data3$before <= 165)*1 + (data3$before > 165)*2
View(data3)
data3$Group <- (data3$before <= 165)
# Creating categories
data3$Group <- (data3$before <= 165)*1 + (data3$before > 165)*2
data3$Group.f <- factor(data3$Group, labels=c("low", "high"))
View(data3)
for(i in 1:5){
print(sum(data3[[i]]))
}
ifelse(data3$before <= 165, "low", "high")
data3$Group2 <- ifelse(data3$before <= 165, "low", "high")
View(data3)
data3$Group2 <- ifelse(data3$before <= 165, "low",
ifelse(data3$before <= 200, "medium", "high"))
View(data3)
data3$Group2 <- ifelse(data3$before <= 165, "low",
ifelse(data3$before <= 175, "medium", "high"))
View(data3)
which(data3$Group2 == "medium")
apply(data2, 1, mean)
apply(data2, 2, mean)
t1 <- apply(data2, 2, mean)
write.table(t1, "table1.csv", sep=",", dec=".")
library(ggplot2)
library(ggvegan)
data('pyrifos')
week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24))
dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11))
mod <- prc(pyrifos, dose, week)
want <- colSums(pyrifos)
## selber nachbauen mit fortify
fobj <- fortify(mod)
select <- want
title = NULL
subtitle = NULL
caption = NULL
legend.position = "top"
## levels of factors - do this now before we convert things
TimeLevs <- levels(fobj$Time)
TreatLevs <- levels(fobj$Treatment)
## convert Time to a numeric
fobj$Time <- as.numeric(as.character(fobj$Time))
## process select
ind <- fobj$Score != "Sample" # Species
if(missing(select)) {
select <- rep(TRUE,sum(ind))
} else {
stopifnot(isTRUE(all.equal(length(select), sum(ind))))
}
## samples and species "scores"
samp <- fobj[!ind, ] # Sample
spp <- fobj[ind,]
plt <- ggplot(data = samp,
aes_string(x = 'Time', y = 'Response', group = 'Treatment',
colour = 'Treatment'))
## add the control
plt <- plt + geom_hline(yintercept = 0)
## add species rug
plt <- plt +
geom_rug(data = spp,
sides = "r",
mapping = aes_string(group = NULL, x = NULL,
colour = NULL, linetype = NULL))
## add the coefficients
plt <- plt + geom_line() +
theme(legend.position = legend.position) +
scale_x_continuous(breaks = as.numeric(TimeLevs), minor_breaks = NULL)
# Labels
plt <- plt + geom_text(data=spp, aes(x = 25, y = spp$Response, label = spp$Label), size = 3) +
coord_cartesian(xlim = c(-4, 25), # This focuses the x-axis on the range of interest
clip = 'off') +   # This keeps the labels from disappearing
theme(plot.margin = unit(c(1,3,1,1), "lines")) # This widens the right margin
## add labels
if(missing(xlab)) {
xlab <- 'Time'
}
if(missing(ylab)) {
ylab <- 'Treatment'
}
plt <- plt + labs(x = xlab, y = ylab, title = title, subtitle = subtitle,
caption = caption)
plt
plt <- ggplot(data = samp,
aes_string(x = 'Time', y = 'Response', group = 'Treatment',
colour = 'Treatment'))
## add the control
plt <- plt + geom_hline(yintercept = 0)
## add species rug
plt <- plt +
geom_rug(data = spp,
sides = "r",
mapping = aes_string(group = NULL, x = NULL,
colour = NULL, linetype = NULL))
plt + geom_line() +
theme(legend.position = legend.position) +
scale_x_continuous(breaks = as.numeric(TimeLevs), minor_breaks = NULL)
plt <- plt + geom_line() +
theme(legend.position = legend.position) +
scale_x_continuous(breaks = as.numeric(TimeLevs), minor_breaks = NULL)
plt + geom_text(data=spp, aes(x = 25, y = spp$Response, label = spp$Label), size = 3) +
coord_cartesian(xlim = c(-4, 25), # This focuses the x-axis on the range of interest
clip = 'off') +   # This keeps the labels from disappearing
theme(plot.margin = unit(c(1,3,1,1), "lines")) # This widens the right margin
plt <- plt + geom_text(data=spp, aes(x = 25, y = Response, label = Label), size = 3) +
coord_cartesian(xlim = c(-4, 25), # This focuses the x-axis on the range of interest
clip = 'off') +   # This keeps the labels from disappearing
theme(plot.margin = unit(c(1,3,1,1), "lines")) # This widens the right margin
plt
