haotu : an open lab notebook

2018/01/03

All Pairwise Combinations of Rownames from a Square Matrix

Filed under: R, R, R spatial, R Stats, Uncategorized — Tags: , , , — S @ 12:37
combn(rownames(my.square.matrix), m=2, FUN=paste, collapse = "-", simplify = T)
Advertisements

2017/12/11

read file from parent folder of current working directory

Filed under: Manipulate Data in R, R, R, R Stats, Uncategorized — Tags: , — S @ 08:10

If  your working directory is C:Parent/Child

Then to read a file from Parent use ..

file="../MY_FILE.RData"

https://stackoverflow.com/questions/24319168/how-to-move-backward-parent-folder

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

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.

Older Posts »

Blog at WordPress.com.