aller Use sapply(), lapply(), vapply() when the data is data frame or list and use apply() when the data is matrix. Because matrix does not have the “direction”, e.g., row-wise or column-wise, to apply the function. So it has to be explicitly given.
apply(data, 2, FUN) # for example, column-wise application of the FUN
Category: status
-
Use sapply(), lapply(), vapply() when th …
-
Difference between “[” and “[[” in R …
Difference between “[” and “[[” in R
Those are operators for elements in R.
The difference between the two is that “[” slices the data while “[[” extracts the data.
The reason is “[[” iterates to get the data.
The manual says it in this way; “[” keep the name while “[[” drops the name, which is hard for me to understand what it means.
Example,nx <- c(Abc = 123, pi = pi) nx[1] nx[[1]]
The difference between "[" and "[[" is more prominent when they are used with c()
z <- list(a = list(b=9, c= c("helo", "world")), d=1:5) z[[c(1,2)]] returns the first and the second elements of z which are all a and d. On the other hand, z[[c(1,2)]] returns the second element of the first element which is the list c.
-
Extracting a fixed position data from th …
Extracting a fixed position data from the list of vectors
I don’t exactly understand how this works but it works.v <- list(c(1,2), c(3,4), 5, c(-3:3)) sapply(v, "[", i = 2) or sapply(v, function(x) x[2]) https://stat.ethz.ch/pipermail/r-help/2007-November/145936.html
-
Hash in R? Use names() ex. nucleotide …
Hash in R?
Use names()
ex.
nucleotide <- 1:4 names(nucleotide) <- c("A", "T", "G", "C") -
Resource for programming in R http://zo …
Resource for programming in R
http://zoonek2.free.fr/UNIX/48_R/02.html -
Smoothing or moving average use ksmooth …
Smoothing or moving average
use ksmooth()
when kernel is “box”, it is the same as moving average by filter() except that ksmooth() can handle the edges better.
Example
ksmooth(data, kernel = “box”, bandwidth = 3) -
Great illustration of plot and margin in …
Great illustration of plot and margin in R
http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/index.htm -
2nd axis in R Use axis. side is where t …
2nd axis in R
Use axis. side is where the second axis goes. Side 3 is the top x-axis. Side 4 is the right y-axis. With put the 1st axis thick for the at and lab is for the text.
Here is the example.
axis(side=3, at = c(0.1, 0.2, 0.3, 0.4, 0.5), lab = c(10, 5, 3, 2.5, 2)) -
When the forward search of readline is n …
When the forward search of readline is not working.
$ stty -a
$ stty -ixon -
yank and put (copy and paste) between tw …
yank and put (copy and paste) between two gVim
Use * instead of +
e.g.
yank: *y
cut: *x
put: “*gPOn the other hand, use + to copy and paste to other programs
yank: +y
cut: +x
paste: “+gP