Displaying 20 results from an estimated 20000 matches similar to: "Creating list from matrix"
2009 Feb 12
3
get top 50 correlated item from a correlation matrix for each item
Hi,
I have a correlation matrix of about 3000 items, i.e., a 3000*3000
matrix. For each of the 3000 items, I want to get the top 50 items that
have the highest correlation with it (excluding itself) and generate a
data frame with 3 columns like ("ID", "ID2", "cor"), where ID is those
3000 items each repeat 50 times, and ID2 is the top 50 correlated items
with ID,
2010 Mar 09
3
Removing Zeros from matrix
Hi Everybody,
I have a matrix of about 45 columns. Some of the rows contain zeros. Using
>data1<-data[complete.cases(data),], I can remove the "NA" rows. But I am
unable to tackle that of zeros.
Can anybody give me an idea of how to remove rows containing zeros in a
matrix.
Thanks so much
Best
Ogbos
[[alternative HTML version deleted]]
2009 May 24
2
Deleting columns from a matrix
useR's,
I have a matrix given by the code:
mat <-
matrix(c(rep(NA,10),1,2,3,4,5,6,7,8,9,10,10,9,8,NA,6,5,4,NA,2,1,rep(NA,10),1,2,3,4,NA,6,7,8,9,10),10,5)
This is a 10x5 matrix containing missing values. All columns except the
second contain missing values. I want to delete all columns that contain
ALL missing values, and in this case, it would be the first and fourth
columns. Any column
2009 Feb 24
1
replace zeros in a block diagonal matrix with small random values?
Hi All.
Imagine you have a large block diagonal matrix. I'd like to replace
the zeros in this matrix with small random (runif) numbers. Any ideas
for a simple and efficient way to do this?
Best regards,
Rick DeShon
2009 Feb 17
2
Efficient matrix computations
Hi,
I am looking for two ways to speed up my computations:
1. Is there a function that efficiently computes the 'sandwich product' of
three matrices, say, ZPZ'
2. Is there a function that efficiently computes the determinant of a
positive definite symmetric matrix?
Thanks,
S.A.
[[alternative HTML version deleted]]
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
2005 Jan 11
4
Matrix to "indexed" vector
I have a matrix that I want to turn into a transformed matrix that
includes the indices from the original matrix and the value. The
matrix is simply real-valued and is square (and large (8k x 8k)). I
want something that looks like (for the 3x3 case):
i j value
1 1 1.0
1 2 0.783432
1 3 -0.123482
2 1 0.783432
2 2 1.0
2 3 0.928374
and so on....
I can do this with for loops, but there is
2010 Sep 03
2
Matrix to list
Dear all, suppose I have following matrix:
> mat <- matrix(rnorm(25), 5)
>
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] 0.97056228 -1.3278509 -0.73511792 2.1650629 -0.4411997
[2,] 0.58613700 -0.2559899 -1.18334248 -1.4990907 1.8138846
[3,] -1.03333313 2.0227887 0.89622681 0.6483973 -1.5523283
[4,] 0.38968833 0.2490004 -0.02301061 -0.2705150
2011 Mar 08
1
Replacing values in a data.frame/matrix
Hi all,
Suppose we have the following matrix
m <- matrix(c(1,2,3,2,1,3,3,1,2), ncol = 3, byrow=T)
where in each row each number occurs only once.
I'd like to define a permutation, e.g. 1 -> 2, 2 -> 1, 3 -> 3 and apply
it to the matrix. Thus, the following matrix should result:
m.perm <- matrix(c(2,1,3,1,2,3,3,2,1), ncol = 3, byrow=T)
i.e. each 1 should map to 2 and vice
2009 Apr 29
3
selecting ith rows of a matrix
Hi all,
If I have a huge matrix/ dataframe and I want to create a new matrix/
dataframe with every second (or third, or fourth etc.) row of the original
matrix, how can I do it? Any help much appreciated.
Thanks,
Umesh
[[alternative HTML version deleted]]
2009 Jun 17
1
Coerce rectangular matrix to symmetrical square matrix
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have a rectangular matrix of size 920 by 85. I'd like to coerce it into a
square matrix such that all row/col names are present in the new matrix and the
additional values are zero.
As an example:
A B C D
A 1 2 3 4
E 5 6 7 8
F 9 10 11 12
Would be coerced to:
A B C D E F
A 1 2 3 4 5 9
B 2 0 0 0 6 10
C 3 0 0
2009 Jan 11
3
Converting Numerical Matrix to List of Strings
Hi all,
Given a matrix:
> mat
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 3 3 3
[3,] 1 1 1
[4,] 2 1 1
How can I convert it to a list of strings:
> desired_output
[1] "aaa" "ttt" "ccc" "gcc"
In principle:
1. Number of Column in matrix = length of string (= 3)
2. Number of Row in matrix = length of vector ( = 4).
3.
2010 Oct 15
4
split data with missing data condition
Dear all
I have data like this:
x y
[1,] 59.74889 3.1317081
[2,] 38.77629 1.7102589
[3,] NA 2.2312962
[4,] 32.35268 1.3889621
[5,] 74.01394 1.5361227
[6,] 34.82584 1.1665412
[7,] 42.72262 2.7870875
[8,] 70.54999 3.3917257
[9,] 59.37573 2.6763249
[10,] 68.87422 1.9697770
[11,] 19.00898 2.0584415
[12,] 60.27915 2.5365194
[13,] 50.76850
2010 Mar 11
2
divid the rows of the matrix by the cector
Hi,
I have a matrix with m rows and n column and a vector with n elements. I
want to divid each rows of the matrix by vector direcly.
could you please hint me?
Thank you
khazaei
2009 Aug 10
2
strsplit a matrix
Dear all,
I am trying to split a matrix into 2 as efficiently as possible.
It is a character matrix:
1 2 3
1 "2-271" "2-367" "1-79"
2 "2-282" "2-378" "1-90"
3 "2-281" "2-377" "1-89"
I want to make 2 matrices from this, as succinctly and efficiently as
possible.
I've tried such
2010 Sep 06
3
Aggregate certain rows in a matrix
Hi,
I have a matrix that looks like this
a <- c(1,1,1,1,2,2,3,3,3,3)
b <- c(2,2,2,3,4,4,4,5,5,6)
c <- c(1,2,3,4,5,6,7,8,9,10)
M <- matrix(nr=10,nc=3)
M[,1] <- a
M[,2] <- b
M[,3] <- c
> M
[,1] [,2] [,3]
[1,] 1 2 1
[2,] 1 2 2
[3,] 1 2 3
[4,] 1 3 4
[5,] 2 4 5
[6,] 2 4 6
[7,] 3 4 7
2009 Jan 09
1
[Fwd: Excluding data with apply]
Dear all,
I've got many responses to my initial question, which is stated below.
However, from those responses it has become clear that I need to
rephrase my problem. All responses dealt with subscripting the data
matrix before 'apply' is run on it. But this is not want I wanted to do.
'apply' cycles through rows or columns of a matrix, and runs a function
on each row or
2010 Aug 03
4
Need help on upper.tri()
HI, I am really messing up to make a symmetrical matrix using upper.tri() & lower.tri() function. Here is my code:
> set.seed(1)
> mat = matrix(rnorm(25), 5, 5)
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] -0.6264538 -0.8204684 1.5117812 -0.04493361 0.91897737
[2,] 0.1836433 0.4874291 0.3898432 -0.01619026 0.78213630
[3,] -0.8356286 0.7383247
2010 Feb 21
4
replicate matrix
Hi all,
I have a matrix, for example
[,1] [,2]
[1,] 1 3
[2,] 4 6
I want to replicate the matrix twice and add an extra column at the end,
which is
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 3 1 3 1 3 2
[2,] 4 6 4 6 4 6 5
I found 'rep' only works for vector. Does anyone know how to replicate a
matrix, and append the matrix?
2008 Jun 29
3
Interactive plot
Hi all,
I have created following codes :
mat = cbind(c(0.000059710430,0.000023057380), c(0.000023057380, 0.00005971089))
set.seed = 1000
vary = runif(dim(mat)[1], 2000, 3000)
calc = function(mat, vary)
{
result = vector(length = (length(vary)+1))
result[1] = sqrt(t(vary) %*% vary)
for (i in 1 : length(vary))
{
result[(i+1)] = sum(vary)*sum(vary*mat[,i])