forked from xingyaochen/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logTrans.Rmd
60 lines (48 loc) · 1.44 KB
/
logTrans.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: "Log Transforming the Data"
author: "Xingyao Chen"
date: "6/21/2017"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
mydat_small=read.csv('pollinator_visitation_fullData.csv')
mydat_small$Experiment.Week=as.factor(mydat_small$Experiment.Week)
mydat_small$Plant.Number=as.factor(mydat_small$Plant.Number)
mydat_small$Pair=as.factor(mydat_small$Pair)
```
#Make some adjustments before Log10-ing
```{r}
mydat_small=mydat_small[,-1]
boo=c()
for (i in 1:ncol(mydat_small)){
boo[i]=is.numeric(mydat_small[,i])
}
#Cannot take the log of 0, so added a small value to each column that contains 0's
mydat_small_val_log=mydat_small
mydat_small_val_log$Honeybees=mydat_small_val_log$Honeybees+1
mydat_small_val_log$Speed=mydat_small_val_log$Speed+0.1
#log10 transformation happenning
for(i in 1:ncol(mydat_small_val_log)){
if(boo[i])
mydat_small_val_log[,i]=log10(mydat_small_val_log[,i])
}
#peek
summary(mydat_small_val_log)
data_dt=split(mydat_small_val_log, mydat_small$Date)
###median as theshold value
theshold=c()
wholedf=data.frame()
for( i in 1:length(data_dt)){
theshold[i]=median(data_dt[[i]]$Honeybees)
data_dt[[i]]$visits=(data_dt[[i]]$Honeybees>=theshold[i])
wholedf=rbind(wholedf, data_dt[[i]])
}
mydat_small_val_log$visits=wholedf$visits
head(mydat_small_val_log)
write.csv(mydat_small_val_log,'pollinator_visitation_fullData_logTrans.csv')
```