Displaying 20 results from an estimated 40000 matches similar to: "sort (all columns of) a matrix"
2005 Feb 21
3
Sorting a matrix on two columns
Hello,
If a matrix with 5 columns has been defined and the first two columns
need to be sorted in ascending order, how can this be achieved whilst
ensuring the
other 3 columns data are in relative position to the sorted columns?
Glen Jones
[[alternative HTML version deleted]]
2011 Sep 23
1
sorting multiple columns of a matrix
Hi,
I have a question about how to sort a matrix for multiple columns.
dat<-sample(0:1,1000,replace=T)
matrix(dat,ncol=5,nrow=200)->x
I want to order like the following:
x[order(x[,1],x[,2],x[,3],x[,4],x[,5]),]->x
My problem: the number of columns of the matrix to be sorted is variable, in
any way I would like to sort for all columns from 1:ncol(x). How to achieve
this?
Best
2008 Jul 31
2
sort rows of matrix by rows of another matrix
Hello all,
I am trying to sort rows of one matrix by rows of another. Given a1 and a2:
------
> a1
[,1] [,2] [,3]
[1,] 7 6 8
[2,] 4 2 4
[3,] 4 7 2
[4,] 0 3 8
a1 <-
structure(c(7, 4, 4, 0, 6, 2, 7, 3, 8, 4, 2, 8), .Dim = c(4L, 3L))
> a2
[,1] [,2] [,3]
[1,] 101 102 103
[2,] 101 102 103
[3,] 101 102 103
[4,] 101 102 103
a2 <-
2007 Feb 22
2
rgl update: please test!
(This is bcc'd to a list of people who have had problems with rgl lately
or who are known to be big users; not cc'd, so you don't all get cc'd
all the responses on the R-devel list).
I've just put together a test build of rgl, and put it on my web site as
http://www.stats.uwo.ca/faculty/murdoch/software/rgl_0.70.564.tar.gz
(source)
and
2007 Feb 05
1
rgl.snapshot "failed"
Dear Roger Koenker,
I have had just the same problem (rgl.snapshot returns "failed") on my
Fedora Core 6 system.
It took me quite a while to figure out the solution, so I would like to
post it here to make others' lives easier.
My configuration:
Linux zachariasz.dns6.org 2.6.18-1.2869.fc6 #1 SMP Wed Dec 20 14:51:19
EST 2006 i686 athlon i386 GNU/Linux
Fedora Core 6
R version
2012 May 18
3
Sort across multiple csv
Dear R help list,
I am very new to R and I apologize in advance if this has been answered
before. I have done my best to google/R search what I need but no luck.
Here is what I am attempting:
I have hundreds of .csv files that I need to sort based on a single column
of alphanumeric data. All of the files contain matrices that have
identical dimensions and headers, however the data table
2010 Feb 26
2
sort columns
Hello,
i have a 50*100 matrix, with real numbers. How do i sort each column?
Now i sort it with a for-loop but this take a lot of time...
Thank you,
Frederik
[[alternative HTML version deleted]]
2013 Jan 25
3
Removal of columns from matrix where all values of the column are identical.
Hi all,
I'd like to write a piece of code which will remove columns from a matrix, if the column contains only one value, say every value in the column is a "3":
Matrix <- matrix(NA, nrow=5, ncol=4)
Matrix[,1] <- c(1,2,3,4,5)
Matrix[,2] <- c(3,3,3,3,3)
Matrix[,3] <- c(5,4,3,2,1)
Matrix[,4] <- c(5,1,4,3,2)
[,1] [,2] [,3] [,4]
[1,] 1 3 5 5
[2,] 2
2006 Jun 21
3
sort matrix by sum of columns
Hi all,
I would like to know how can I sort the cols of a matrix by the sum of
their elements.
a <- matrix(as.integer(rnorm(25,4,2)),10,5)
colnames(a) = c("alfa","bravo","charlie","delta","echo")
I guess I should use colSums, and then rearrange the matrix somehow
according to the result.
My idea is to display a "sorted" barplot:
2011 Apr 19
2
Data frame with 3 columns to matrix
Dear R Users,
Lets assume I have this data frame:
x y z
1 1.00 5 0.5
2 1.02 5 0.7
3 1.04 7 0.1
4 1.06 9 0.4
x and y columns are sorted and the values not necessarily integers. z
values are not sorted. Now I would like to create a matrix out of this
with x as first column values and y as first row values. Matrix element
a_11 shall be left NA. The a_ij should have the z value for the
2008 Sep 22
4
sort a data matrix by all the values and keep the names
Dear all,
If I have a data frame x<-data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)):
x1 x2 x3
1 4 8
7 6 2
I want to sort the whole data and get this:
x1 1
x3 2
x2 4
x2 6
x1 7
x3 8
If I do sort(X), R reports:
Error in order(list(x1 = c(1, 7), x2 = c(4, 6), x3 = c(8, 2)), decreasing = FALSE) :
unimplemented type 'list' in 'orderVector1'
The only way
2010 Feb 01
1
matrix columns
Hello.
I am working with a set of variables which are in columns. Three of them
are of the same length while one has a different length. Typing
'>data<-matrix(c(ca$value, mo$value,b2$value, y1), ncol = 3)'
appears to read any three columns out of the four, though I can say exactly
which of these three columns are read.
However, typing '> data<-matrix(c(ca$value,
2010 Sep 01
2
getting column names of row-by-row sorted matrix
Hi folks,
I want to sort a matrix row-by-row and create a new matrix that contains the corresponding colnames of the original matrix.
E.g.
> set.seed(123)
> a <- matrix(rnorm(20), ncol=4); colnames(a) <- c("A","B","C","D")
> a
A B C D
[1,] -0.56047565 1.7150650 1.2240818 1.7869131
[2,]
2012 Nov 07
2
simple coversion of matrix rows to matrix columns
Dear All
I would like to convert matrix rows to columns. I am thinking the t() function should help, but am having a hard time converting the matrix into the dimensions I would like them to. Example:
a <-matrix(c(1:30),ncol=3) gives me:[,1] [,2] [,3]
[1,] 1 11 21
[2,] 2 12 22
[3,] 3 13 23
[4,] 4 14 24
[5,] 5 15 25
[6,] 6 16 26
[7,] 7 17
2012 Sep 08
3
Apply a function to columns of a matrix
Dear All,
as a follow up to my previous e-mail (I think I am getting closer...):
I am trying to apply the trapezoidal functions to a matric column by column. I have the following code:
a <-matrix(c(1:100),ncol=10)
b <-matrix(c(2,4,6,8,10,12,14,16,18,20))
apply(a,2,function(b,a) sum(diff(b)*(a[-1]+a[-length(a)]))/2)
for some reason i get an error message:
Error in FUN(newX[[, i],
2010 Sep 23
1
looking for a faster way to compare two columns of a matrix
Please consider this matrix:
x <- structure(c(5, 4, 3, 2, 1, 6, 3, 2, 1, 0, 3, 2, 1, 0, 0, 2, 1,
1, 0, 0, 2, 0, 0, 0, 0), .Dim = c(5L, 5L))
For each pair of columns, I want to calculate the proportion of entries
different than 0 in column j (i > j) that have lower values than the entries
in the same row in column i:
x[, 1:2]
sum((x[,1] > x[,2]) & (x[,2] > 0))/sum(x[,2] > 0)
2008 Jun 24
2
insert new columns to a matrix
Instead of prepend or append new columns to a matrix, how to insert them to a matrix ? For example, I would like to insert 3 new columns after the 5th column of matrix m.
_________________________________________________________________
[[elided Hotmail spam]]
[[alternative HTML version deleted]]
2009 May 27
3
Sort matrix by column 1 ascending then by column 2 decending
I've got a matrix with 2 columns and n rows. I need to sort it first
by the values in column 1 ascending. Then for values which are the
same in column 1, sort by column 2 decending. For example:
2 .5
1 .3
1 .5
3 .2
Goes to:
1 .5
1 .3
2 .5
3 .2
This is easy to do in spreadsheet programs but I can't seem to work
out how to do it in R and haven't been able to find a solution
anywhere.
2005 Jun 16
1
regressing each column of a matrix on all other columns
DeaR list
I would like to predict the values of each column of a matrix A by
regressing it on all other columns of the same matrix A. I do this with
a for loop:
A <- B <- matrix(round(runif(10*3,1,10),0),10)
A
for (i in 1:length(A[1,])) B[,i] <- as.matrix(predict(lm( A[,i] ~
A[,-i] )))
B
It works fine, but I need it to be faster. I've looked at *apply but
just can't
2003 Jul 18
3
lexicographic sort of ordered lists
Does anyone know how to execute the following sort problem in R? Matrix X
has positive integer entries, and each column has been sorted in ascending
order. The problem is now to order the columns lexicographically. For
instance if the matrix X is
1 2 1 1 2
2 2 3 3 2
3 5 5 4 2
then the result should be
1 1 1 2 2
2 3 3 2 2
3 4 5 2 5
Let ONE be a vector of 1's of length