similar to: sorting multiple columns of a matrix

Displaying 20 results from an estimated 30000 matches similar to: "sorting multiple columns of a matrix"

2011 Sep 23
2
image function help required
Hi, I have a question concerning the image function and how to generate custom axis labels: dat<-sample(0:1,1000,replace=T) matrix(dat,ncol=5,nrow=200)->x x[order(x[,1],x[,2],x[,3],x[,4],x[,5]),]->x I would like to have a heatmap kind of thing like this: image(t(x),col=c(0,1),axes=F) axis(1, 1:5, c(colnames(x))) I only do see parts of the axis (only an "A" is
2014 Apr 14
7
¿Cómo generar informes con R sin utilizar LaTeX?
Hola a tod@s, quiero generar informes con los resultados de R en formato pdf preferiblemente. Actualmente estoy utilizando knitr junto con LaTeX. Y ya conozco el resto de formatos de salida de knitr como: markdown, html, ... ¿Alguien conoce otras alternativas? He visto algo de jasper report por ahí, pero desconozco cómo poder comunicarlo con R. Muchas gracias por adelantado. -- Víctor Nalda
2010 Sep 20
5
Sorting and subsetting
Suppose I have a data frame, such as the one below: tmp <- data.frame(index = gl(2,20), foo = rnorm(40)) And further assume it is sorted by index and then by the variable foo. tmp <- tmp[order(tmp$index, tmp$foo) , ] Now, I want to grab the first N rows of tmp for each index. In the end, what I want is the data frame 'result' tmp1 <- subset(tmp, index == 1) tmp2 <-
2010 Apr 08
2
subsetting a matrix with specified no of columns
Hello! All, I am working on 10000x1000 matrix say 'mat' and i want to subset this matrix in a fashion that in new matrix i get columns 2,3,9,10,16,17,23,24.......so on. That is pair of columns after every interval of 7. I tried following but i got an error which is obvious. >dim(mat) [1] 10000 10 >a=mat[,c(seq(c(2,3),ncol(mat),7))] Warning messages: 1: In if (n < 0L)
2011 Oct 14
1
sorting dataframe by arbitrary order
This has been dogging me for a while. I've started making a lot of tables via xtable so the way I want to sort things is not always in alphabetical or numerical order. As an example, consider I have a dataframe as follows set.seed(100) a <- data.frame(V1=sample(letters[1:4],100, replace=T),V2=1:100) I know I can sort the columns first by V1 first and then by V2 by: sorted.a <-
2010 May 06
5
Apologies : question on transforming a table
Dear R-help list, Apologies. I am trying to convert one table to another. It feels that it should be a very straightforward answer with a single (or two) commands with the right extensions, but I really can't figure this out right now. I have several hundred pheno factors actually, so manually doing this line by line is not an option. My original table is approximately like this : ID
2011 Apr 11
3
sort.int(S3object) strips class but not the is.object flag
If x has an S3 class then sort.int(x) returns a value without an S3 class but which has the is.object flag set, which, I think, causes identical() give a false/misleading report: > x <- structure(1:3, class="unrecognizedClass") > y <- sort.int(x) > t <- 1:3 > identical(y, t) # expect TRUE [1] FALSE > identical(as.vector(y), as.vector(t)) # expect
2010 Sep 16
3
get top n rows group by a column from a dataframe
Hi, is there an R function like sql's TOP key word? I have a dataframe that has 3 columns: company, person, salary How do I get top 5 highest paid person for each company, and if I have fewer than 5 people for a company, just return all of them? Thanks, Richard [[alternative HTML version deleted]]
2011 Mar 14
3
ideas on sorting
Hi, I have a character vector as below: a<-c('10','3R','4','4R','5','5R','6','6R','7','8','9','7R','1','10R','11'
2008 Dec 04
2
How to optimize this codes ?
How to optimize the for-loop to be reasonably fast for sample.size=100000000 ? You may want to change sample.size=1000 to have an idea what I am achieving. set.seed(143) A <- matrix(sample(0:1, sample.size, TRUE), ncol=10, dimnames=list(NULL, LETTERS[1:10])) B <- list() for(i in 1:10) { B[[i]] <- apply(combn(LETTERS[1:10], i), 2, function(x) { sum(apply(data.frame(A[,x]), 1,
2009 Jan 19
1
Floating point excepting when cbind()ing a matrix of grobs (or environments) with a 0-column matrix
library(grid) e <- rectGrob() # OR: # e <- environment() a <- matrix(list(e), ncol = 1, nrow = 2) b <- matrix(ncol = 0, nrow = 2) cbind(a, b) cbind(a, b) This reliably crashes R for me. I realise this is a rather esoteric error condition, but it crops up for me when creating matrices of grobs to be turned into a ggplot2 plot. Hadley -- http://had.co.nz/
2010 Jul 30
3
simple table/matrix problem
Hi Given three vectors x <- c(fish=3, dogs=5, bats=2) y <- c(dogs=1, hogs=3) z <- c(bats=3, dogs=5) How do I create a multi-way table like the following? > out x y z bats 2 0 3 dogs 5 1 5 fish 3 0 0 hogs 0 3 0 ('out' is a matrix). See how the first line shows 'x' has 2 bats, 'y' has zero bats, and 'z' has 3 bats and so on for each
2010 Jun 18
3
Non-procedural access to columns of a matrix
Hi, I would like to have an index for a column in a matrix encoded in a cell of the same matrix. For example: x = matrix(c(11,12,13,1, 21,22,23,3, 31,32,33,2),byrow=T,ncol=4) In this case, column 4 is the index. I then access the column specified in the index by: > for (i in 1:3) print(x[i,x[i,4]]) [1] 11 [1] 23 [1] 32 > > for (i in 1:3) {x[i,x[i,4]] <- x[i,x[i,4]] + 5} > x
2009 Apr 13
3
toupper does not work in sub + regex
Hi, I don't know what I am doing wrong to the toupper does not seem working in sub + regex. The following returns 's' not the upper class 'S' as I expect: sub("q_([a-z])[a-zA-Z]*",toupper('\\1'),"q_sviRaw") Can someone tell me where I did wrong? Thanks, Richard [[alternative HTML version deleted]]
2011 Feb 03
2
Sorting a Data Frame by hybrid string / number key
Hi, I'm trying to present a table of some experimental data, and I want to order the rows by the instance names. The issue I've got is that there are a variety of conventions for the instance names (e.g. competition01, competition13, small_1, big_20, med_9). What I want to be able to sort them first in category order so: competition < small < med < big, and then perform the
2013 Apr 16
4
Singular design matrix in rq
Quantreggers: I'm trying to run rq() on a dataset I posted at: https://docs.google.com/file/d/0B8Kij67bij_ASUpfcmJ4LTFEUUk/edit?usp=sharing (it's a 1500kb csv file named "singular.csv") and am getting the following error: mydata <- read.csv("singular.csv") fit_spl <- rq(raw_data[,1] ~ bs(raw_data[,i],df=15),tau=1) > Error in rq.fit.br(x, y, tau = tau, ...) :
2009 Aug 26
3
changing equal values on matrix by same random number
Dear all, I have about 30,000 matrix (512x512), with values from 1 to N. Each value on a matrix represent a habitat patch on my matrix (i.e. my landscape). Non-habitat are stored as ZERO. No I need to change each 1-to-N values for the same random number. Just supose my matrix is: mymat<-matrix(c(1,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 3,3,0,0,0,0,0,0,0,4,4,
2009 Mar 24
3
Summarizing each row into a frequency table
I have a matrix containing -1, 0, 1, however certain rows will not have all 3 numbers. I have written some codes to compute the frequency table of how many -1s, 0s, 1s per row, but it is very ugly and not efficient if there are more than 3 numbers. Please suggest. m <- rbind(sample(0:1, replace=T, 10), sample(-1:1, replace=T, 10)) m.table <- t(apply(m, 1, function(x) c(sum(x==-1, na.rm=T),
2014 Apr 15
2
Fwd: ¿Cómo generar informes con R sin utilizar LaTeX?
Victor, Me parece que podrías investigar si Scribus puede generar e insertar la salida de R en sus documentos, por lo que estás agregando a tu pregunta me parece que BI no es el camino. Si lo haces, creo que a más de uno en esta lista le interesará la experiencia. La alternativa sugerida por Emilio usando Rthml y CSS con probablemente markdown y, yo agregaría, pandoc me resulta muy interesante y
2005 Jun 14
2
Plotting rows (or columns) from a matrix in different graphs, not using "par"
Dear R-users, I would like to ask whether it's possible (for sure it would be), to plot each rows (or columns) in different graphs and in the same figure region without using the function "par" and then struggling around with "axes" and labels etc. Luckily, I would always have "rows + columns = even number" and the same "ylim". The next one could be a