Displaying 20 results from an estimated 10000 matches similar to: "Matrix transformation problem"
2008 Oct 20
5
Combining all possible values of variables into a new...
I'm trying to create a new column in my data.frame where subjects are categorized depending on values on four other columns. In any other case I would just nest a few ifelse statements, however, in this case i have 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I wonder if there is a more efficient way of doing this.
For illustrational purposes, let's say
2005 Aug 17
2
power of a matrix
Dear all,
I have a population with three age-classes, at time t=0 the population
is:
n.zero <- c(1,0,0)
I have a transition matrix A which denotes "fertility" and "survival":
A <- matrix(c(0,1,5, 0.3,0,0, 0,0.5,0), ncol=3, byrow=TRUE)
To obtain the population at t=1, I calculate:
A %*% n.zero
To obtain the population t=2, I calculate:
A %*% (A %*% n.zero)
... and so
2009 Feb 09
2
Counting session days
hi,
I have some session data in a dataframe, where each session is recorded with a start and a stop date. Like this:
session_start session_stop
===================
2009-01-03 2009-01-04
2009-01-01 2009-01-05
2009-01-02 2009-01-09
A session is at least one day long. Now I want a dataframe with 'active sessions' per date. Like this:
date active_sessions
=============
2009-01-01 1
2007 Jan 23
4
Vector to Matrix transformation
Hi R,
I have a vector V1 of unknown length, say n. I need to convert this into
a matrix C of row size=5, and accordingly the column should be updated.
I tried with:
C=as.matrix(V1,5,n/5)
But it is not working...Could somebody help me on this?
Thanks in advance...
[[alternative HTML version deleted]]
2010 Jan 29
2
RMySQL, Sweave and the annoying TRUE echo
Hi,
A small (but annoying) problem with RMySQL library. When a connection is closed, it echoes 'TRUE' to the console. Like this:
R> mysqlCloseConnection(con)
[1] TRUE
The real problem comes when I use RMySQL with Sweave, since the TRUE echo gets into my final Sweave document. Even when I explicitly state <<include=FALSE, echo=FALSE>>= in the header of the R code chunk.
2010 Jan 26
3
Formatting cgroup and factor level labels in Hmisc latex function
I'm trying to typeset at simple crosstable with the Hmisc latex function. And I have two problems.
1. How do I make all columns the same width? The Latex function seems very unwilling to break the 'cgroup' labels and the factor level labels. Please have look at this screenshot that shows my problem:
>> http://hem.passagen.se/stpe9096/table.png
So, how can I make sure that the
2008 May 08
2
applying cor.test to a (m, n) matrix
Hi everybody,
I would like to apply cor.test to a matrix with m rows and n columns and get the results in a list of matrices , one matrix for p.val, one for the statistic, one for the correlation and 2 for upper and lower confidence intervals, something analog with cor() applied to a matrix.
I have done my own function to get a matrix of p.values and i suppose i can build similar functions for
2008 Jan 15
2
Looking for simpler solution to probabilistic question
Hi
I have two processes which take with a certain probability (p1 and p2) x
number of years to complete (age1 and age2). As soon as thge first
process is completed, the second one begins. I want to calculate the
time it takes for the both processes to be completed.
I have the following script which gives me the answer, butI think there
must be a more elegant way of doing the calculations
2010 May 17
2
Dynamically build variable names
I'm trying to dynamically build variable names to use on a list. Let's say I have a list like this one:
l <- list(V1_1=c(1,2,3), V1_2=c('One','Two','Three'))
And I succesfully build my variable name like this:
paste('l$', 'V1_1', sep='')
Why can't I just run a mean call with the pasted variable name?
mean(paste('l$',
2011 Mar 24
1
Two matrix loop
Hi,
I'm trying to create a distance matrix. And it works out somewhat ok. However, I suspect that there are
some efficiency issues with my efforts. Plz have a look at this:
donor <- matrix(c(3,1,2,3,3,1,4,3,5,1,3,2), ncol=4)
receiver <-
matrix(c(1,4,3,2,4,3,1,5,1,3,2,1,4,5,3,5,1,3,2,4,5,1,2,3,1,4,5,5,1,2,1,3,4,3,2,5,5,1,4,2,5,4,3,2), ncol=4)
The above creates my two matrices. I have
2005 Jun 02
4
repeated vector in matrix
Hallo,
I'll need a matrix with n rows of the an identical vector.
> h
[1] 3 3 3 3 2 2 2
The nmatrix should look like this:
> x<-rbind(h,h,h)
> x
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
h 3 3 3 3 2 2 2
h 3 3 3 3 2 2 2
h 3 3 3 3 2 2 2
but I need n rows which must be variable. Can anyone help me?
thanks Andreas
2006 Aug 25
2
horizontal direct product
II am translating some gauss code into R, and gauss has a matrix
product function called the horizontal direct product (*~), which is
some sort of variant on the Kronecker product.
For example if x is 2x2 and y is 2x2
the horizontal direct product, z, of x and y is defined (in the Gauss
manual) as:
row 1 = x11*y11 x11*y12 x12*y11 x12*y12
row 2 = x21*y21 x21*y22 x22*y21 x22*y22
Or in R
2007 Nov 22
1
Matrix of dummies from a vector
Hallo
>From a variable "x" that defines, say, four classes, I would like to define
the matrix "mat" of dummy variables indicating the classes, i.e.
x <- c(1,1,1,1,2,2,2,3,3,3,4,4)
mat <- matrix(c(1,0,0,0,
1,0,0,0,
1,0,0,0,
1,0,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,1,
0,0,0,1), ncol=4, byrow=T)
Thank you for your help,
Serguei
2005 Nov 04
2
Simplify iterative programming
Dear,
I am looking for the simplification of a formula to improve the
calculation speed of my program. Therefore I want to simplify the
following formula:
H = sum{i=0..n-1 , [ sum {j=0..m-1 , sqrt ( (Ai - Bj)^2 + (Ci -
Dj)^2) } ] }
where:
A, C = two vectors (with numerical data) of length n
B, D = two vectors (with numerical data) of length m
sqrt = square root
Ai = element of A with index
2007 Jul 22
3
create an array with rep
Hi,
I want to make the following array of numbers:
-3 -3 -3 -3 -3 -3 -3 -2 -2 -2 -2 -2 -2 -2 ... 3 3 3 3 3 3 3
-3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 ... -3 -2 -1 0 1 2 3
(3 would be N, a painful example to type number).
Here is my dirty attempt to do it,
> N<-3
>
> x<-c(-N:N)
>
> rj<-rbind(matrix(outer(matrix(1,1,2*N+1),x),nrow=1),rep(x,2*N+1))
>
It
2007 Jul 13
1
counting occurances of matching rows in a matrix
I need help regarding to the following problem:
Consider this matrix:
> M <- matrix(c(1,2, 4,3, 1, 2),3, 2, byrow=TRUE)
> M
[,1] [,2]
[1,] 1 2
[2,] 4 3
[3,] 1 2
I would like to have a matrix which counts the identical rows and places the counts into its third column. I tried with ftable():
> as.data.frame(ftable(M[,1], M[,2]))
Var1 Var2 Freq
1 1 2
2008 Jun 11
3
searching for specific row in matrix
Hi,
I have matrix of bits and a target vector. Is there an
efficient way to search the rows of the matrix for the target?
I am interested in the first row index where target is found.
Example:
> source("lookup.R")
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 1 1 0
[2,] 1 1 0 1 0
[3,] 0 0 1 0 0
[4,] 1 0 0 1 1
[5,]
2004 Nov 25
4
Creating lists from matrices
Hello,
I am using R 1.9.1 on Windows 2000 SP4. I have the following problem:
Say I have a matrix,
>my.matrix
[,1] [,2] [,3]
[1,] "A" "B" "C"
[2,] "D" "E" "F"
[3,] "G" "H" "I"
I would like to apply an operation to this matrix which returns a list my.list
containing the
2007 Mar 08
2
Removing duplicated rows within a matrix, with missing data as wildcards
I'd like to remove duplicated rows within a matrix, with missing data
being treated as wildcards.
For example
> x <- matrix((1:3), 5, 3)
> x[4,2] = NA
> x[3,3] = NA
> x
[,1] [,2] [,3]
[1,] 1 3 2
[2,] 2 1 3
[3,] 3 2 NA
[4,] 1 NA 2
[5,] 2 1 3
I would like to obtain
[,1] [,2] [,3]
[1,] 1 3 2
[2,] 2 1 3
2011 Sep 28
1
Password protected R Repository
Hi,
I've set up a very simple R repository. Just a single source
library. Everything works fine. I can install the package on my client
using:
install.packages(repos='http://www.myServer.se/myRepo/',
pkgs='myLib', dep=TRUE)
However, I want to protect the repo, so I use a
.htaccess, placed directly under 'myRepo' on the server. I use
'Authentication Basic' and