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")
Advertisements

find non-ascii in R

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

2015/01/30

aggregate more than one column in data.table

Filed under: R — Tags: , , , , — S @ 11:15
# Average ability by grade
agg1<- fm1[, j=list(mean(x0, na.rm = TRUE),mean(x1, na.rm = TRUE)),by = key]

http://rprogramming.net/aggregate-data-in-r-using-data-table/

2014/08/17

add row to data frame when there are factors

Filed under: Manipulate Data in R, R, R Stats — Tags: , , — S @ 06:49

In general I do not like factors in my data frames, and while there are good reasons to have them, my work typically does not require it. So when trying to amend or add to data frames using rbind these hidden factors cause problems. The easiest solution I have found is to turn those factors into character vectors using the following code.

 

i <- sapply(df.coords, is.factor)
df.coords[i] <- lapply(df.coords[i], as.character)
df.coords<-rbind(df.coords,my.addition)

2014/08/16

install all packages from task view in R

Filed under: R, R Stats — Tags: , , — S @ 08:13

Use the ctv package to install all of the packages that are listed in an R taskview

library(ctv)
install.views("Spatial")

2013/03/18

Get the R code for the functions of a package

Filed under: Uncategorized — Tags: , , , , , — S @ 03:58

Download the tab ball from Cran and extract the gz to get the tar. Then extract the tar.

 

I use 7zip since it is free!

 

Look in the R folder, the code you are searching for will be there.

Blog at WordPress.com.