Displaying 20 results from an estimated 8000 matches similar to: "Moving data in a dataset"
2012 Jun 19
2
how to use by function
hi all,
Assume I have data like
data<-rbind(c(1,2),c(1,3),c(2,1),c(3,2),c(3,4))
I want to get some matrix like
1,2,3
2,NA,NA
3,2,4
I'm using by
mat<-matrix(NA,3,3)
by(data,data[,1],mat[data[,1],]<-c(data[,2]))
but it doesn't work.
Any ideas?
thanks,
cowboy
2003 Mar 19
2
Time Series-like barplot?
I have data structured like the following:
> foo.mat <- matrix(NA, ncol = 5, nrow = 10)
> foo.mat[2:6,1] <- 1
> foo.mat[1:3,2] <- 1
> foo.mat[3:10,3] <- 1
> foo.mat[1:10,4] <- 1
> foo.mat[8:10,5] <- 1
> foo.mat
[,1] [,2] [,3] [,4] [,5]
[1,] NA 1 NA 1 NA
[2,] 1 1 NA 1 NA
[3,] 1 1 1 1 NA
[4,] 1 NA 1 1
2009 Sep 21
5
More elegant way of excluding rows with equal values in any 2 columns?
Hello, dear R-ers!
I built a data frame "grid" (below) with 4 columns. I want to exclude
all rows that have equal values in ANY 2 columns. Here is how I am
doing it:
index<-expand.grid(1:4,1:4,1:4,1:4)
dim(index)
# Deleting rows that have identical values in any two columns (1 line of code):
2011 Sep 04
1
output and save multiple dataset from a function: sorry I could not figure out this....
Dear list:
Before going into my problem, R list has been awesome for me ...thank you
for the help. I have a simple problem, however I could get a answer to it...
#my data
myseed <- c(1001:1030)
gend <- function(x){
set.seed(x)
var <- rep(1:4, c(rep(4, 4)))
vary <- rnorm(length(var), 50, 10)
mat <- matrix(sample(c(-1,0,1), c(10*length(var)), replace = TRUE), ncol =
10)
mydat <-
2010 Aug 29
1
Finding functions of large dataset for numerical integration
Hello everyone,
I have been trying to figure out away to integrate under a spline produced
by the package tps(fields). As the package does not output functions I am
trying to do something similar to the trapezium rule. My data are 3D (x, y &
z). I have extracted from the surface output by Tps the values of z at
regular intervals so that I have a grid of figures, for example:
1 4 6 6 8
8
2010 Jun 19
2
Call by reference or suggest workaround
I have written code to compute multi-indices in R [1] and due to the
recursive nature of the computation I need to pass around the *same*
matrix object (where each row corresponds to one multi-index). As pass
by reference wasn't the default behavior I declared a global matrix
(mat) and used the <<- operator to write to the global matrix. So the
usage would be to call genMultiIndices(3,2)
2009 Sep 10
2
index of min elements in matrix
Hi, All,
How can I get the indices of the minimum elements in a matrix without using
a loop?
For example, if the matrix is
4 5 2
2 8 9
5 2 3
Then I want to output (1,3), (2,1), (3,2).
Thanks,
Annie
[[alternative HTML version deleted]]
2010 Jun 15
2
Integration problem: error in invoking an outside function
Dear all,
Currently I am trying to integrate a function which depends on four
variables, two of which are given, one is given in the integrate function,
so there is one variable to integrate on.
The code is as follows:
Pmatrix =
function(th) {
P = matrix(nrow=6, ncol=6, data=0)
P[1,1] = P[2,1]=P[3,2]=P[4,3]=P[5,4]=P[6,5]= exp(-th)
P[,6] = 1-exp(-th)
return(P)}
lim.verd =
2012 Feb 27
5
macro function
hi,
I know how to use the "for" loop function like:
for(i in 1:ncol(mat)){
mat[i]<-b[i,2]
}
but, in this case
r1<-b[1,1]
r2<-b[2,1]
r3<-b[3,1]
r4<-b[4,1]
*
*
*
r3002<-b[3002,1]
r3003<-b[3003,1]
- must make vectors
how should I make a efficient code for that?
Is there anything in R like SAS MACRO function?
Please help me.
--
View this message in context:
2013 Mar 27
1
Passing arguments between apply and l(s)apply functions vs. nested for loop
Hi R community,
I have a question concerning passing arguments between apply and lapply? Or maybe, once my problem is explained, the question is really about how to best transform my nested for loops into list/matrix operations; I am just beginning this transformation away from nested for loops, so I beg of you to have some lenience regarding my ignorance.
Part I:
I used a set of nested for
2010 Apr 16
3
VERY SIMPLE QUESTION
Dear R users,
I am looking for more efficient way to compute the followings
--------------------------------------------------------------------------
a <- matrix(c(1,1,1,1,2,2,2,2),4,2)
b <- matrix(c(1,2,3,4),4,1)
Eventually, I want to get this matrix, `c`.
c <- matrix(c(1/1,1/2,1/3,1/4,2/1,2/2,2/3,2/4),4,2)
--------------------------------------------------------------------------
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all,
I have a problem with the "subset()" function. I spent all day yesterday
with a collegue to solve it and we did not find a satisfying solution (even
in the archived mails), so I ask for your help.
Let's say (for a simple example) a matrix mat:
R> mat
cola colb colc
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
My goal is to select the lines of the matrix on the basis of the
2005 Apr 14
4
data manipulation
Hello,
my question is about the data handling.
I have a data set that is lined as:
4 1 17 1 1
-5.1536 -0.1668 -2.3412 -0.5062 0.9621 0.3640 0.3678 -0.5081 -0.2227
0.8142 -0.0389 -0.0445 -0.0578 -0.1175 -0.1232 0.8673 -0.1033 -0.0796
-0.0341 -0.1716 -0.1801 -0.7014 0.6578 0.5611
4 1 17 2 1
-5.1536 -0.1668 -2.3412 -0.5062 0.9621 0.3640 0.3678 -0.5081 -0.2227
0.8142 -0.0389 -0.0445
2004 Jul 23
4
hang up when going to voicemail
I have a little menu set up where hitting 1, 2, or 3 places the call through
to a cellular phone over IAX. That works. However, if caller hits 4 to go
into voicemail, the system hangs up. Am I doing something wrong in the dial
plan, or is this a CVS change? I had no trouble with this until I upgraded
to about 07/21 CVS, and I'm on 07/23 [latest] now with same results.
My dial plan:
2004 Dec 21
3
R code for var-cov matrix given variances and correlations
Dear list members,
Where can I find code for computing the p*p variance-covariance
matrix given a vector of p variances (ordered varA, varB, ...,
varp) and a vector of all possible correlations (ordered corAB,
corAC, ..., corp-1,p)?
I know that the covariance between 2 variables is equal to the
product of their correlation and their standard deviations:
corAB * varA^.5 * varB^.5
and so:
2008 Dec 26
3
Problem: no such extension 'xx' in context 'default'
Hi Guys,
I am not so familiar with asterisk and hope to get help here. I am having now some stupid errors. My goal for the first, is to create a simple pbx with different context.
As long as I use only the contex 'default' everything seems to work perfect. Now I tried to add another context i.e 'internal' and the asterisk is complaining
for not finding the required extension in
2006 Jul 19
2
trellis.focus with postscript device
Hello.
First: R 2.3.1 on Windows XP.
I am trying to add information (sample size) to the Trellis strips which
I am successful using the trellis.focus function with the default
Windows device. However, I typically use the postscript device as I use
LaTeX and \includegraphic for incorporating graphs into stat reviews.
Here's some example code (apologies for the lack of creativity and
2008 Mar 26
2
Moving data between R and Matlab back and forth?
Hi to the list,
I am trying to find a way to painlessly move structured data back and
forth between R and Matlab (also Octave). For this purpose I found the
R.matlab package great help. I wish to use a Matlab -v6 MAT file as an
intermediary format, because it is well read by both Matlab and
Octave. It is also well read by 'readMat' function in R.matlab
package, but that is where I run
2009 Jan 07
1
Re moving Numeric,0 from dataframe
I realize i am breaking the posting rules by not posting sample code but i
tried building some sample test code for this problem based on my working
code and it wasnt producing what i wanted so hopefully a brief explanation
and my result will allow you guys enough information to offer some advice.
My result:
allTAZprobs TAZS
[1,] Numeric,0 640
[2,] 0.4385542 641
[3,] 0.2876207 642
[4,]
2011 Dec 13
2
Inverse matrix using eigendecomposition
General goal: Write R code to find the inverse matrix of an nxn positive
definite symmetric matrix. Use solve() to verify your code works.
Started with a 3x3 matrix example to build the code, but something dosen't
seem to be working. I just don't know where I am going wrong.
##Example matrix I found online
A<-c(4,1,-1,1,2,1,-1,1,2)
m<-matrix(A,nrow=3,ncol=3)
##Caculate the eigen