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


check a phylo object

Filed under: Uncategorized — Tags: , , — S @ 09:07

See here:


or forked



new faster code for PGLMM

Filed under: Uncategorized — Tags: , , — S @ 11:50



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]



BLAST from R

Filed under: Uncategorized — Tags: , , , , , , — S @ 08:16

There is a nice post here on the topic
The post takes code from the blastSequences function in the R package annotate

However, the code does give an object with enough info to then retrieve the sequences. I edited this code to be able to perform BLASTs in R for a given organism filter. The returned object gives gene ids and definitions.

You can find my cleaned and edited code is here

Error in write.table because data.frame contains a list

Filed under: Uncategorized — Tags: , , , — S @ 06:42

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol, :
unimplemented type 'list' in 'EncodeElement'

I got this error when trying to write a table write.table on an object. The object was a data.frame but one of the elements was a list (it is unclear why it was a list, just R magic). The simplest workaround is to convert the data.frame to a matrix as.matrix and save that object with write.table


fill in missing data in R

Filed under: Uncategorized — Tags: , — S @ 10:34


The impute package developed for microarrays can replace missing (NA) data in an R matrix by its nearest neighbor values.


make and check directories in R

Filed under: Manipulate Data in R, R, R Stats — Tags: , — S @ 07:32


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)
Older Posts »

Blog at WordPress.com.