This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jd1 <- read.csv("datetime.csv") | |
## Then a new variable called timestamp will be added to the dataframe jd1. | |
jd1 <- transform(jd1, timestamp=as.POSIXct(paste(Date,Time),format="%Y/%m/%d %H:%M")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GET EQUATION AND R-SQUARED AS STRING | |
# SOURCE: http://goo.gl/K4yh | |
lm_eqn = function(df){ | |
m = lm(y ~ x, df); | |
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2, | |
list(a = format(coef(m)[1], digits = 2), | |
b = format(coef(m)[2], digits = 2), | |
r2 = format(summary(m)$r.squared, digits = 3))) | |
as.character(as.expression(eq)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(grid) | |
# A viewport taking up a fraction of the plot area | |
vp <- viewport(width = 0.4, height = 0.4, x = 0.1, y = 0.9,just=c("left","top")) | |
b_plot <- ggplot(cars,aes(speed,dist))+geom_line()+xlim(10,15) | |
b_plot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Let us assign a sample date as first with hours, minutes and seconds. | |
## It is also recommended to use the time zone | |
> date <- as.POSIXct("2013-06-14 16:34:26",tz="GMT") | |
## Convert to Julian date using the following function | |
> jddd <- julian(date, origin = as.POSIXct("2013-01-01 00:00:00",tz="GMT")) | |
> jddd | |
Time difference of 164.6906 days | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{beamer} | |
\usetheme{CambridgeUS} | |
\setbeamertemplate{items}[ball] | |
\usefonttheme[onlylarge]{structurebold} | |
\usecolortheme[RGB={205,173,0}]{structure} | |
\setbeamerfont*{frametitle}{size=\normalsize,series=\bfseries} | |
\useoutertheme{infolines} | |
%Pacakges | |
\usepackage{xcolor} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multiple plot function | |
# | |
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) | |
# - cols: Number of columns in layout | |
# - layout: A matrix specifying the layout. If present, 'cols' is ignored. | |
# | |
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), | |
# then plot 1 will go in the upper left, 2 will go in the upper right, and | |
# 3 will go all the way across the bottom. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [y,coef,window,Cx,Ff] = lanczosfilter(x,varargin) | |
%LANCZOSFILTER Filters a time series via Lanczos method (cosine filter). | |
% [Y,coef,window,Cx,Ff] = LANCZOSFILTER(X,dT,Cf,M,pass) Filters the time | |
% series via the Lanczos filter in the frequency space (FFT), where | |
% | |
% INPUTS: | |
% X - Time series | |
% dT - Sampling interval (default: 1) | |
% Cf - Cut-off frequency (default: half Nyquist) | |
% M - Number of coefficients (default: 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function to convert velocity xy EFDC file to velocity component file | |
velxy_convert <- function(file){ | |
process_pp_template <- function(path) { | |
# Read data using quicktoolsr function | |
dat <- readts_EE(path) | |
# Reshape the data from long format to wide format | |
dat_mod <- dcast(dat, time ~ id) | |
return(dat_mod) | |
} | |
# Read the file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import files under folder name fawn | |
# It is very important to include the option (full.names=TRUE). It it is not included | |
# then you will get the error something like | |
# "Error in file(file, "rt") : cannot open the connection In addition: Warning message: | |
#In file(file, "rt") : cannot open file 'FAWN_2002.csv': No such file or directory | |
mydata=ldply(list.files(path="data/fawn/",pattern="csv",full.names=TRUE),function(filename) { | |
dum=read.csv(filename) | |
dum$filename=filename | |
return(dum) |
OlderNewer