Skip to content

Latest commit

 

History

History
76 lines (61 loc) · 1.75 KB

miscR.md

File metadata and controls

76 lines (61 loc) · 1.75 KB

divide numerical range to intervals as factor --> cut

right control which side of the interval is closed;

cut(x$s2, breaks = c(0, 1, 5, 10, 20, Inf), right = F)

write an object in string representation in order to write to file or recreate it;

dput(x1)
structure(c(1.88888888888889, 1.3425, 0.859756097560976, 0.596026490066225
), class = "table", .Dim = 4L, .Dimnames = structure(list(c("1",
"2", "3", "4")), .Names = ""))

stop using Reduce(cbind, list)

as cbind and rbind can take multiple arguments, using do.call would be more efficients;

length(ll)

f <- function(x, y, z)
# 3

do.call(f, ll) == f(ll[[1]], [[2]], [[3]])

R packages install --> cannot downloaded

library(BiocInstaller)
chooseCRANmirror()

list the size of all objects

for (obj in ls()) { message(obj); print(object.size(get(obj)), units='auto') }

comandline install with R CMD INSTALL

export R_LIBS="/home/your_username/R_libs"
 R CMD INSTALL -l /home/your_username/R_libs pkg_version.tar.gz

Q: compare with NAs;

> NA > 0.5 & F
[1] FALSE
> NA > 0.5 & T
[1] NA

how to plot multiply symbol 'x':

plot(0)
for(i in 1:4)
    text(1, 0.2*i, bquote( x[.(i)] == .(pnorm(i)) %*% 10^2 ))

for a list of plotmatch syntax: https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html

remove useless attributes from object:

# view all attributes of a data.frame:
names(attributes(x))

# keep only first 3 attributes (first 3 are usually name, row.names, class)
attributes(x) <- attributes(x)[1:3]

capture output of print:

niceprint <- function(x) cat(paste0('# ', capture.output(x)), sep = '\n')