Displaying 20 results from an estimated 30000 matches similar to: "Matrix manipulation"
2012 Aug 21
1
About matrix manipulation
Dear list,
I'm trying to create a matrix by combining the sites that species occur in
a new matrix with species as rows and sites as columns.
The main matrix is "mat":
mat <- as.data.frame(cbind(sp1=c(rep(0, 5), rep(1, 5)),sp2=sample(c(rep(0,
6),rep(1, 4))),
fac=c(rep("a", 3), rep("b", 3),rep("c", 4))))
The first two columns are species and the
2010 Jul 09
2
C module causing rounding errors?
Hi all!
I am currently writing a C-module for a for loop in which I permute columns
in a matrix (bootstrapping) and I send a couple of variables into C
initially. All of it is working, except the initial values I send to R are
rounded/truncated (I believe rounded).
I am using a 32 bit machine to compile, I am using (I believe) 32 bit R....
While debugging I print the values I am sending to C,
2010 Nov 29
1
Extracting selected rows from a matrix
Hi,
I have matrix of 104 columns and 30000 rows (Each Row has rowname).
I have 13 different list of selected rownames (character) say 1000 each. Now I want to extract the all the columns according to the rownames in each the list.
How can I do that in R ?
1 ) For a single list
2) For all the 13 list at a time
Regards,
Pankaj Barah
Department of Biology,
Norwegian University of
2008 May 19
2
Sort matrix with duplicate row names alphabetically by rowname
Hi,
I've a matrix that contains 4 replicates of each rowname. (4 a's, 4
b's, 4 c's in no particular order) Like this:
#
c 32
a 1
b 4
c 87
c 34
b 54
a 23
a 12
b 9
a 3
b 87
c 43
There are a couple of more columns but I'm using the above as an example
I need to sort it so that the same rownames appear together in
alpahbetical order. Like this:
#
a 1
a 23
a 12
a 3
b 4
2011 Mar 16
2
export list to csv
Hi everybody.
I have list like this:
l<-list(data.frame(q1=c(1,2,"check"),q2=c(3,"check",5)),
data.frame(q1=c("check",1),q2=c(4,5)))
names(l)<-c("A","B")
rownames(l[[1]])<-c("aa","bb","cc")
rownames(l[[2]])<-c("aa","bb")
Every object has the same number of columns but different number
2013 Apr 29
1
Need help on matrix calculation
Hello again,
Let say I have 1 matrix:
Mat <- matrix(1:12, 4, 3)
rownames(Mat) <- letters[1:4]
Now I want to subscript of Mat in following way:
Subscript_Vec <- c("a", "e", "b", "c")
However when I want to use this vector, I am geting following error:
Mat[Subscript_Vec, ]
Error: subscript out of bounds
Basically I want to get my final matrix
2011 May 27
1
How to convert an ftable object to a matrix including the row names?
Dear expeRts,
What's the easiest way to convert an ftable object to a matrix such that the
row names of the ftable object are shown in the first couple of columns of the
matrix? This is (typically) required, for example, when the final goal is to print
the matrix via xtable.
Below is a rather complicated example of how to do it...
Cheers,
Marius
## Goal: convert an ftable() to a
2009 Dec 08
1
data manipulation/subsetting and relation matrix
Hi List,
Here is some example data.
myDat <- read.table(textConnection("group id
1 101
1 201
1 301
2 401
2 501
2 601
3 701
3 801
3 901"),header=TRUE)
closeAllConnections()
corr_mat <-read.table(textConnection("1 1 .5 0 0 0 0 0 0 0
2 .5 1 0 0 0 0 0 0 0
3 0 0 1.0 0 0 0 0 0 0
4 0 0 0 1 .5 .5 0 0 0
5 0 0 0 .5 1
2008 Feb 15
2
wire.frame tick labels from matrix
Dear R Users, close to the end of this I used wireframe to create a 3D plot
from a matrix. The x and y axis tick labels (1-6) for each were created
from the matrix being a 6X6 matrix. I need the axis tick labels to be the
row and column headings which you can see in the output (mat.x). I have
tried several work arounds, but they have not been successful.
Thanks in advance. keith
rm(list=ls())
2003 Nov 10
3
Reading an upper triangular matrix
Hola!
I have data in the form of a symmetric distance matrix, in the file I
have recorded only the upper triangular part, with diagonal. The
matrix is 21x21, and the file have row and col names, and some other
information. I am trying to read with the following code (I tried
many variations on it, but all give the same error). The items in the
data file is delimited by white space.
(Part
2010 Mar 23
2
Adding matrix rows that have the same name?
Does anyone know if there is an R function that will take a matrix like this
jim 1 0 0 0 0 0
jim 0 1 0 0 0 0
jim 0 0 1 0 0 0
bob 1 0 0 0 0 0
bob 0 0 1 0 0 0
harry 0 0 1 0 0 0
harry 0 0 0 1 0 0
harry 0 0 0 0 1 0
harry 0 0 0 0 0 1
and make it like this? (that is, add together rows that have the same name?)
jim 1 1 1 0 0 0
bob
2017 Jan 19
2
Error en loop anidado con data.table
Hola tengo una tabla de tipo data.frame "datos" con la siguiente
estructura, simplificada en número de niveles por variable, para crear un
ejemplo más sencillo:
id anio t_8a t_10a t_12a rankf8 rankf10 rankf12
1 1 100 220 220 NA NA NA
2 1 140 350 350 NA NA NA
3 2 55 165 165 NA NA NA
4 2 60 200 200 NA NA NA
5 2 100 NA NA NA NA NA
6 3 NA 350 350 NA NA NA
También tengo una matriz,
2010 Sep 01
2
Legend with fill = gray ?
Hi,
I am facing a problem with the legend, I don?t know how to use the fill
option in the legend in order to achieve the same standard gray levels
that are plotted.
Sorry for this easy one, but I really did not find anything so far.
It works fine with color:
###### C O L O R
mat <- matrix(2,3,rep(2,6))
rownames(mat)<-c("A","B","C")
par(xpd=T,
2012 Dec 05
3
data manipulation between vector and matrix
Dear list,
I was curious how to subtract a vector from matrix?
Say, I have
mat <- matrix(1:40, nrow=20, ncol=2)
x <-c(1,2)
I want,
x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements
of x against column elements in mat.
But x-mat won't do it.
Thanks,
Mike
[[alternative HTML version deleted]]
2011 Jul 01
1
Reverse legend label order in barplot
Hi list,
I've thus far not found a solution to my problem and hope someone can help.
I have a data matrix and wish to plot a stacked bar plot using barplot().
This is simple enough, but I have a problem with the legend labels being in
the reverse order from what I want. The default appears to have labels
ascending bottom-to-top reflecting bottom-to-top sub-bars, but I would like
the
2007 Feb 26
1
Adding duplicates by rows
Hi,
I am trying to add duplicates of matrix "mat" by row. Commands
subset(mat,duplicated(rownames(mat)))
or
mat[which(duplicated(rownames(mat))),]
return only half of the required indices. How can I find the remaining
ones, ie the matches, so that I can add them up?
Thanks,
Serguei
___________________________________________________________________
Austrian Institute of Economic
2008 Jan 04
3
slow access to matrix dimnames
hello,
i have been trying to convert my data frames to matrices in the hopes of
speeding up some of my more complicated scripts.
to assist with this, i am trying to create a "matrix column operator"
like $:
"%$%" = function(data,field) {
as.numeric(data[,grep(field,unlist(dimnames(data)[2]))])
}
the idea here is that you can use a matrix like a dataframe:
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings,
My goal is to create a Markov transition matrix (probability of moving from
one state to another) with the 'highest traffic' portion of the matrix
occupying the top-left section. Consider the following sample:
inputData <- c(
c(5, 3, 1, 6, 7),
c(9, 7, 3, 10, 11),
c(1, 2, 3, 4, 5),
c(2, 4, 6, 8, 10),
c(9, 5, 2, 1, 1)
)
MAT <- matrix(inputData,
2004 Jul 30
2
pairwise difference operator
There was a BioConductor thread today where the poster wanted to find
pairwise difference between columns of a matrix. I suggested the slow
solution below, hoping that someone might suggest a faster and/or more
elegant solution, but no other response.
I tried unsuccessfully with the apply() family. Searching the mailing
list was not very fruitful either. The closest I got to was a cryptic
chunk
2006 Mar 25
2
pairwise combinatons of variables
Dear WizaRds,
although this might be a trivial question to the community, I was unable to
find anything solving my problem in the help files on CRAN. Please help.
Suppose I have 4 variables and want to use all possible combinations:
1,2
1,3
1,4
2,3
2,4
3,4
for a further kmeans partitioning.
I tried permutations() of package e1071, but this is not what I need. Thank you
for your help and