haotu : an open lab notebook


save rda data file with compression

Filed under: errors in R, R, R, R Stats — Tags: , , , , — S @ 06:36

find non-ascii in R

Filed under: errors in R, R, R, R Stats, Uncategorized — Tags: , , , , — S @ 06:34


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]



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)


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



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.