cherche femme du kirghizstan Prevent drop dimension attribute by drop = FALSE.
test.matrix <- matrix(1:15, nc=5) > test.matrix[1, ] [1] 1 4 7 10 13 > test.matrix[1, , drop=FALSE] [,1] [,2] [,3] [,4] [,5] [1,] 1 4 7 10 13
cherche femme du kirghizstan Prevent drop dimension attribute by drop = FALSE.
test.matrix <- matrix(1:15, nc=5) > test.matrix[1, ] [1] 1 4 7 10 13 > test.matrix[1, , drop=FALSE] [,1] [,2] [,3] [,4] [,5] [1,] 1 4 7 10 13
Subscripting in R
[ gives the same data type as the data it is applied to.
[[ and $ extract the element and the data type is not necessarily the same as that of the data it is applied to.
$ does partial matching.
[ and [[ don’t.
$ does not evaluate.
[ and [[ evaluate their arguments.
declare a list and adding an element in R
test.list <- list() test.list[['key']] <- value # adding an element test.list[['key']] # retrieve the element
R plot with examples
http://www.harding.edu/fmccown/r/
Title for muti plots in R
mtext(‘Title’, outer=TRUE)
search()
list loaded packages.
vector -> lapply -> list
array, matrix -> apply -> vector, array, list
Using a value of a variable in title
Use paste and eval.
plot(x, main = paste("Cluster", eval(i))
Links: Clustering methods in R
Clustering using standard R functions
http://www.statmethods.net/advstats/cluster.html
Using heatmat and heatmap.2
http://www2.warwick.ac.uk/fac/sci/moac/students/peter_cock/r/heatmap/
Drawing k-means clusters on heatmap and introducing pheatmap
http://stackoverflow.com/questions/5084077/r-draw-kmeans-clustering-with-heatmap
Calling R from Perl
Synopsis
use Statistics::R;
my $R = Statistics::R->new();
$R->startR;
$R->send(q`postscript("file.ps" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`);
$R->send(q`plot(c(1, 5, 10), type = "l")`);
$R->send(q`dev.off()`);
$R->send(qq`x = 123 \n print(x)`);
my $ret = $R->read;
print "\$ret : $ret\n";
$R->stopR();