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/03/10

check a phylo object

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

See here:

https://github.com/emmanuelparadis/checkValidPhylo

or forked

https://github.com/mrhelmus/checkValidPhylo

2015/02/02

new faster code for PGLMM

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

https://github.com/willpearse/pez/blob/master/R/pglmm.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/11/07

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

2014/10/15

fill in missing data in R

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

http://www.bioconductor.org/packages/release/bioc/manuals/impute/man/impute.pdf

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

2014/09/05

make and check directories in R

Filed under: Manipulate Data in R, R, R Stats — Tags: , — S @ 07:32
if(!file.exists("data"))
{
dir.create("data")
}

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

Create a free website or blog at WordPress.com.