haotu : an open lab notebook

2016/06/24

save rda data file with compression

Filed under: errors in R, R, R, R Stats — Tags: , , , , — S @ 06:36
save(mydata,file="mydata.rda",compress="xz")

find non-ascii in R

Filed under: errors in R, R, R, R Stats, Uncategorized — Tags: , , , , — S @ 06:34
tools::showNonASCII(readLines("myfiles.R"))

2016/04/22

add unique id to duplicated grouped rows

Filed under: Manipulate Data in R, R, R, Uncategorized — S @ 12:30
library(plyr)
id(x)

2016/04/18

stack rasters with different extents etc..

Filed under: arcmap, R, R, R spatial, R Stats, Uncategorized — S @ 13:42
two<-resample(two,one)
stack(one,two)

2016/02/22

true copy of a data.table

Filed under: Manipulate Data in R, R — S @ 10:13
mycopy<-copy(DT)

2016/02/19

Join polygons like countries from mapdata

Filed under: arcmap, R, R, R spatial — S @ 13:28
library(maps)
library(mapdata)
library(maptools)
library(rgeos)

DR<-map(database = 'worldHires',regions="Dominican Republic",fill=TRUE)
 IDs<-DR$names
 DR<-map2SpatialPolygons(DR,IDs, proj4string=CRS("+proj=longlat +datum=WGS84"))
Haiti<-map(database = 'worldHires',regions="Haiti",fill=TRUE)
 IDs<-Haiti$names
 Haiti<-map2SpatialPolygons(Haiti,IDs, proj4string=CRS("+proj=longlat +datum=WGS84"))
Hispaniola<-gUnion(DR, Haiti)
plot(Hispaniola)

Note fill=TRUE

2015/01/22

add column in data.table

Filed under: Manipulate Data in R, R, R, R Stats — S @ 07:09
DT[,new1:=v$r1]

 

Here is a post to add multiple columns to a data.table

http://stackoverflow.com/questions/11308754/add-multiple-columns-to-r-data-table-in-one-function-call

2014/02/05

R ls() search

Filed under: R — Tags: , , , — S @ 02:31
ls(pattern="tree")

From

x <- 1:10
f <- function() ls()
g <- function() ls(envir=.GlobalEnv)
h <- function() ls(envir=.GlobalEnv, pattern="[fg]")
f()
# character(0)
g()
# [1] "f" "g" "h" "x"
h()
# [1] "f" "g"

http://stackoverflow.com/questions/8142941/how-to-search-an-environment-using-ls-inside-a-function

2013/11/07

Google Chart Tools in R

Filed under: Google, Google Docs, Manipulate Data in R, R, R, R graphics — S @ 03:21

There is a nice R package googleVis that integrates google motion charts and chart tools with R

A tutorial here

2013/08/30

Install quantstrat

Filed under: Finance, R, R — S @ 04:07


install.packages("FinancialInstrument", repos="http://R-Forge.R-project.org")

install.packages("blotter", repos="http://R-Forge.R-project.org")

install.packages("quantstrat", repos="http://R-Forge.R-project.org")

http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/

Older Posts »

Create a free website or blog at WordPress.com.