Displaying 20 results from an estimated 50000 matches similar to: "Re order matrix columns"
2010 Jun 10
2
adding column of ordered numbers to matrix
Hello everyone,
I have a matrix of over 40000 line and about 30 columns.
For my analysis I would like to add another column with ascending numbers
(column header should be "order", and than 1,2,3,4 ....the end of the
matrix).
During my analysis I reorder them ( due to merge commands by a different
column).
How do I add such a column in an ascending order (or descending for what it
2009 Jun 26
3
Compute correlation matrix for panel data with specific ordering
Hello All,
I have a panel date - here a small-scale example:
df <-
data.frame(cbind(rep(c("AUT","BEL","DEN","GER"),4),cbind(rep(c(1999,2000,2001,2002),4)),sample(10,16,replace=T)))
names(df) <- c("country","year","x")
SORT <- c("GER","BEL","DEN","AUT")
I need to compute the
2005 May 31
1
Add Columns and Order for Rbind?
I am using rbind to add one list with one row to another master list. The
problem is that not all columns exist in both lists.
What methods would you recommend to reorder one list based on the column
names of another? If both sets have the same order and columns, I can
then use rbind. I can live with columns being added to the master list set
it makes the task easier using something like
2010 Dec 09
2
Reshape Columns
Hello,
I have a general formatting question. I have two columns of data:
ColA <- c("m", "m", "m", "m")
ColB<- c("d","d","d","d")
And I would like to reorder them into a new column that looks like this:
ColC<-
2004 Aug 28
6
model.matrix.default chokes on backquote (PR#7202)
Full_Name: Gabor Grothendieck
Version: R version 1.9.1, 2004-08-03
OS: Windows XP
Submission from: (NULL) (207.35.143.52)
The following gives an error:
> `a(b)` <- 1:4
> `c(d)` <- (1:4)^2
> lm(`a(b)` ~ `c(d)`)
Error in model.matrix.default(mt, mf, contrasts) :
model frame and formula mismatch in model.matrix()
To fix it replace this line in model.matrix.default:
2008 Feb 12
3
Reorder data frame columns by negating list of names
Hello,
I would like to reorder columns in a data frame by their names as
demonstrated below:
Take this data frame:
> xxx <- data.frame(matrix(1:40, ncol=8))
> names(xxx) <- letters[1:8]
> xxx
a b c d e f g h
1 1 6 11 16 21 26 31 36
2 2 7 12 17 22 27 32 37
3 3 8 13 18 23 28 33 38
4 4 9 14 19 24 29 34 39
5 5 10 15 20 25 30 35 40
and reorder the columns like
2010 Apr 23
3
reordering of matrix rows to maximize the sum of the diagonal
Hi r-help community,
This question isn't so much a syntax/coding one, but here goes:
Let's say I have matrix of arbitrary dimensions and I'd like to
reorder the rows in such a way that I could maximize the sum of the
entries along the diagonal.
For example, for this 3x3 matrix:
[,1] [,2] [,3]
[1,] 3 4 13
[2,] 9 1 2
[3,] 2 11 1
rearranging the rows
2011 Aug 25
1
Sorting order of reorder with multiple variables
I've been building a ranked dot plot for several days now and am sorting the
data using the reorder command. What I don't understand is how reorder
works when mutiple varibles are plotted by grouping. In the example below
I'm using re-order to sort by a variable name Resv_Prop, but I'm plotting up
to three different values of Resv_prop (different Year values) for each
factor.
2009 Nov 20
1
how to specify the order of panels with xyplot
> chromosomes
id refseq name length
1 0 NC_000001.9 Homo sapiens chromosome 1 247249719
2 1 NC_000002.10 Homo sapiens chromosome 2 242951149
3 2 NC_000003.10 Homo sapiens chromosome 3 199501827
4 3 NC_000004.10 Homo sapiens chromosome 4 191273063
5 4 NC_000005.8 Homo sapiens chromosome 5 180857866
6 5 NC_000006.10 Homo sapiens chromosome 6
2010 Jun 05
5
Matrix to Vector
Given a matrix of m*n, I want to reorder it as a vector, using a row major
transpose.
so:
> m<-matrix(seq(1,48),nrow=6,byrow=T)
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 1 2 3 4 5 6 7 8
[2,] 9 10 11 12 13 14 15 16
[3,] 17 18 19 20 21 22 23 24
[4,] 25 26 27 28 29 30 31 32
[5,] 33 34 35 36 37
2009 May 21
2
Re order variables in a dataframe
This is no doubt a very basic question for most R users, but is there an easy
way to reorder the variables (columns) in a dataframe (I can't seem to find
an answer anywhere). I've generally been creating a new dataframe and
selecting the new order I want from the old but this is time-consuming.
Thanks,
Paul
--
View this message in context:
2011 Nov 08
3
ggplot2 reorder factors for faceting
Dear List
I am trying to draw a heatmap using ggplot2. In this heatmap I have faceted my data by 'infection' of which I have four. These four infections break down into two types and I would like to reorder the 'infection' column of my data to reflect this.
Toy example below:
library(ggplot2)
# test data for ggplot reordering
genes <- (rep (c(rep('a',4),
2008 Feb 27
1
how to specify ggplot2 facet plot order
Hi, new to R and ggplot2. I've been trying to get a facet plot in which the
order of the facets is as I require, rather than ordered numerically,
alphabetically, by Roman numerals, mean (answers to these were posted here
after much searching). Here's some test code to demonstrate what I get.
series = c('C2','C4','C8','C10','C15','C20')
ids =
2010 Dec 09
1
order matrix by column position
Hello all,
I'm trying to grasp a way to order a matrix by giving order() only a vector of the columns it can look to for sorting.
The approach has to be generic such that I can feed order() a vector of variable length (ie varying # of columns to sort by).
x<-rep(1,9)
y<-c(1, 1, 2, 2, 2, 1, 2, 2, 2)
z<-c(10, 11, 10, 13, 15,1000,1000, 1001,1002)
results<-cbind(x,y,z)
#pseudocode:
2011 Jan 23
2
Ordering box plots
Hello all, I want box plots by group to display in order of increasing
mean (or median) of each group but can't seem to figure it out and
couldn't find anything on R-seek, either.
My data looks like this:
meas unit sid grade rsprti
1 2.24 1002 99999902 NA 0.8600000
2 3.04 1007 43589520 3 0.9400000
3 4.95 2002 39910470 5 1.5300000
4 2.24 2002 39986280 5
2008 Nov 09
2
Delete rows from matrix having at least one zero value
Hi,
I have a further question about matrix manipulation.
Imagine the following two matrices:
> test
[,1] [,2] [,3] [,4]
[1,] 1 0 6 4
[2,] 2 5 7 5
[3,] 3 6 8 6
[4,] 4 0 0 0
> matrix(is.element(test,0), ncol=4)
[,1] [,2] [,3] [,4]
[1,] FALSE TRUE FALSE FALSE
[2,] FALSE FALSE FALSE FALSE
[3,] FALSE FALSE FALSE FALSE
[4,] FALSE
2012 Jul 22
5
Reorder in decreasing order
reorder() is probably the best way to order the levels in a vector
without manually specifying the order. But reorder() orders by default
in an increasing order: "The levels are ordered such that the values
returned by ?FUN? are in increasing order."
Is there a way to do what reorder() does, but order the levels
according to a _decreasing_ order of the values?
Sverre
2009 Apr 07
2
heatmap.2 no reordering of the columns and rows
Hi,
I need to generate a heatmap on a square matrix and wouldn't want to reorder the columns and the rows on the heatmap display.
I have used the options Rowv=NULL and Colv=NULL but doesn't seem to work. Following is a snippet of the heatmap function i am using.
args <- commandArgs();
inputfile <- args[2]
imgfile <- args[3]
bitmap(imgfile, height=15, width=15, res=100,
2013 Mar 03
1
Ordering Table Columns
cdouglass wrote
> Hello all,
>
> Totally new to this and I'm just doing a frequency distribution analysis
> on T-shirt sales by size. I have a .csv with 60 orders. I read in the
> data using read.csv. If I look at the summary() or table() of the data it
> looks fine, except that the shirt sizes are alphabetical rather than from
> S-XXL--so the bar graph loses the shape
2007 Feb 01
0
traverse through many columns of a matrix in a function
Hello everyone,
Here is the setup.
z is a 119 x 15 matrix, m_index is a 119 x 5 matrix
What I am trying to do is return the results from fitCopula by sequentially
binding all 15 columns of z to the first column of m_index,
(cbind(z[,1],m_index[,1]),(cbind(z[,2],m_index[,1]), etc.
Unfortunately, my code below only binds z[,1] and m_index[,1] and return the
same result 14 times.
Any ideas on