Displaying 20 results from an estimated 10000 matches similar to: "operations on all pairs of columns from two matrices"
2008 Nov 26
2
Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices
My two matrices are roughly the sizes of m1 and m2. I tried using two apply and cor.test to compute the correlation p.values. More than an hour, and the codes are still running. Please help to make it more efficient.
m1 <- matrix(rnorm(100000), ncol=100)
m2 <- matrix(rnorm(10000000), ncol=100)
cor.pvalues <- apply(m1, 1, function(x) { apply(m2, 1, function(y) { cor.test(x,y)$p.value
2008 Jan 29
2
add/subtract matrices, ignoring NA or missing values
Hi,
For example, given two 2x2 matrices m1 and m2. I would like to add/subtract
element by element
> m1
[,1] [,2]
[1,] NA NA
[2,] 1 2
> m2
[,1] [,2]
[1,] 1 NA
[2,] NA 2
> m1 + m2
[,1] [,2]
[1,] NA NA
[2,] NA 4
How can I ignore the NA, and get this ? Hope the solution can be extended to
subtract and modulo also.
[,1] [,2]
2008 Jul 31
4
Identifying common prefixes from a vector of words, and delete those prefixes
For example, c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal"). How can I identify the common prefix is ".is.an.animal" and delete it to give c("dog", "cat", "rat") ?
Thanks
_________________________________________________________________
[[alternative HTML version deleted]]
2009 Jul 28
3
selecting vector elements using matrices and combining the results
I've been scratching my head over this one for too long. I'm hoping
someone out there can solve this riddle.
I have two vectors of characters, v1 and v2, both of length L, and two
matrices of logicals, m1 and m2, both of dimension N*L. The first matrix
of logicals corresponds to the first vector of characters, and the second
to the second.
The matrices are telling me which of the
2012 Apr 10
1
compare two matrices
Dear Members,
I have two estimated transition matrices and I want to compare them.
In fact I want to check the hypothesis if they come from the same process.
I tried to look for some test but all I found was independence test of
contingency tables.
The following code shows that the usual chi-squared test statistic does
not follow chisq distribution.
MCRepl <- 5000
khi12 <- rep(0,MCRepl)
2008 Jun 19
4
Any simple way to subset a vector of strings that do contain a particular substring ?
For example,
strings <- c("aaaa", "bbbb","ccba").
How to get "aaaa", "bbbb" that do not contain "ba" ?
_________________________________________________________________
[[alternative HTML version deleted]]
2010 Apr 14
5
Running cumulative sums in matrices
Dear R-helpers,
I have a huge data-set so need to avoid for loops as much as possible. Can someone think how I can compute the result in the following example (that uses a for-loop) using some version of apply instead (or any other similarly super-efficient function)?
example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)
#The aim is to create a new matrix with every column containing the
2008 Jul 15
5
counting number of "G" in "TCGGGGGACAATCGGTAACCCGTCT"
Any better solution than this ?
sum(strsplit("TCGGGGGACAATCGGTAACCCGTCT", "")[[1]] == "G")
_________________________________________________________________
[[alternative HTML version deleted]]
2008 Nov 25
1
compute pearson correlation p-values for all combinations of columns of 2 matrices
How can I compute the pearson correlation p-values for all combinations of columns of 2 matrices ?
> m <- matrix(rnorm(20), nrow=4, dimnames=list(LETTERS[1:4], letters[1:5]))
> m1 <- matrix(rnorm(20), nrow=4, dimnames=list(LETTERS[1:4], letters[1:5]))
> cor(m,m1)
a b c d e
a -0.67533294 -0.2516151 -0.3780815 0.55816011
2012 Nov 18
1
identical matrices
Dear R users,
I want to check matrices when i change the order of the rows or/and the order of the columns or/and the combination of them
i will give an example what i want
1 -1 1 1 1 1 1 1
-1 -1 -1 -1 -1 -1 -1 -1
1 1 1 1 1 -1 1 1
these 2 matrices are identical because i change the first row and make it third
1 -1 1 1 -1 1 1 1
-1 -1 -1
2008 Sep 13
3
Beautify R scripts in microsoft word
I am generating a report containing several R scripts in the appendix. Is there any way to "beautify" the R source codes in microsoft word, similar to what we see in tinn-R ?
Thanks
_________________________________________________________________
[[alternative HTML version deleted]]
2006 Mar 13
3
hfsc and dropped packets
Hi,
I''m trying to get a handle on hfsc. Here is my configuration:
root@jmnrouter:/jmn# tc class show dev vlan1
class hfsc 1: root
class hfsc 1:1 parent 1: ls m1 0bit d 0us m2 225000bit ul m1 0bit d 0us m2
225000bit
class hfsc 1:10 parent 1:1 rt m1 191000bit d 25.0ms m2 135000bit ls m1 0bit
d 0us m2 135000bit ul m1 0bit d 0us m2 225000bit
class hfsc 1:20 parent 1:1 rt m1 22008bit d
2012 Mar 08
4
Correlation between 2 matrices but with subset of variables
Dear All,
I have two matrices A (40 x 732) and B (40 x 1230) and would like to calculate correlation between them. I can use: cor(A,B, method="pearson") to calculate correlation between all possible pairs. But the issue is that there is one-many specific mappings between A and B and I just need to calculate correlations for those pairs (not all). Some variables in A (proteins, say p1)
2010 Jun 16
2
data frame
Dear list,
I have the following problem. I have a data frame like this
CLUSTER YEAR variable Delta R_pivot
M1 2005 EC01 NA NA
M1 2006 EC01 2 NA
M1 2007 EC01 4 5
M2 2005
2008 Jul 29
1
correlation between matrices - both with some NAs
Hi everyone,
I'm having trouble applying the Cor() function to two matrices, both of
which contain NAs. I am doing the following:
a<-cor(m1, m2, use="complete.obs")
... and I get the following error message:
Error in cor(m1, m2, use = "complete.obs") :
no complete element pairs
Does anyone know how I can apply a correlation, ignoring any NAs?
Thanks,
rcoder
--
2008 Sep 22
1
how to set rownames / colnames for matrices in a list
Hello,
I have another stupid question. I hope you can give me a hint how to solve this:
I have a list and one element is again a list containing matrices, all of the
same dimensions. Now, I'd like to set the dimnames for all matrices:
example code:
m1 <- matrix(1:25, nrow=5)
m2 <- matrix(26:50, nrow=5)
# ... there can be much more than two matrices
l <- list()
l[[1]] <-
2008 Jul 08
4
Can R do this ?
I have a folder full of pngs and jpgs, and would like to consolidate them into a pdf with appropriate title and labels. Can this be done via R ?
_________________________________________________________________
Easily publish your photos to your Spaces with Photo Gallery.
[[alternative HTML version deleted]]
2010 Jun 17
1
big big problem
Dear list,
I'll try to be more clear in explaining my problem. I have a data frame like this called X:
CLUSTER YEAR variable value1 value2
M1 2005 EC01 NA NA
M1 2006 EC01 2 5
M1 2007
2004 Jul 13
1
MLE, precision
Hi, everyone
I am trying to estimate 3 parameters for my survival
function. It's very complicated. The negative
loglikelihood function is:
l<- function(m1,m2,b) -sum( d*( log(m1) + log(m2)
+ log(1- exp(-(b + m2)*t)) ) + (m1/b - d)*log(m2 +
b*exp(-(b + m2)*t) ) + m1*t - m1/b*log(b+m2) )
here d and t are given, "sum" means sum over these
two vairables.
the parameters
2009 Jan 06
2
Generating GUI for r-scripts
Hi,
I have developed some scripts that basically ask for input tab-limited format files, do some processing, and output several pictures or csv. Now I need to have some gui to wrap on top of the scripts, so that end-users can select their input files, adjust some parameters for processing, and select output folder or filenames.
Please advice me if there is any tools or project suitable for