Skip to content

Instantly share code, notes, and snippets.

View janeshdev's full-sized avatar

Janesh Devkota janeshdev

View GitHub Profile
@janeshdev
janeshdev / regression.R
Last active December 18, 2015 11:19
Regression
# 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));
@janeshdev
janeshdev / dateandtime.R
Last active December 15, 2015 00:19
Combine date and time into one variable with POSIXct class
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"))