Displaying 20 results from an estimated 20000 matches similar to: "replace a row in a matrix"
2010 Nov 09
2
simulation from pareto distn
Dear all,
I am trying to simulate from truncated Pareto distribution. I know there is
a package called PtProcess for Pareto distribution...but it is not for
truncated one. Can anyone please help me with this?
Thanks in advance.
Cassie
[[alternative HTML version deleted]]
2011 Apr 08
4
Simulation from discrete uniform
Dear all,
I am trying to simulate from discrete uniform distribution. But I could not
find any in-built code in R. Could anyone help me please?
Thanks in advance for the time and help.
Cassie
[[alternative HTML version deleted]]
2012 Apr 10
1
how to convert seconds to 12 hour time format
Hello everyone,
I am wondering if there is any routine in R which can convert time given in
'seconds' unit to the 12 hour time format. For example, suppose the data
set looks like
x=c(36885,84000,20) #x in seconds
I want to get the output as
[1] " 11:14:45 AM"
[2] " 11:20:00 PM"
[3] "12:20:00 AM"
Does anyone have any idea? Thanks in advance.
Cassie
2010 Sep 29
1
executing loop
Dear All,
I am trying to define a loop for a m*n matrix, where i=1:n and j=1:m. Unlike
the usual for loop, i should go in the following way:
For j=1,
i=1,2,3,....n
For j=2,
i=n,n-1,n-2,......,1
For j=3,
i=1,2,3,.....n etc.
which means i should go in either increasing or decreasing order
alternatively.
Can anyone please help me in doing this?
Thanks,
Cassie
[[alternative HTML version
2011 Sep 28
1
Multiplying a list of matrices with a vector
Hi all!
I have a list of matrices and I want to multiply the ith element of the list with the ith element of a another vector. That is,
> LL <- list(A=diag(3),B=diag(3),C=diag(3))
> vec <- 1:3
> for(i in 1:3)
+ {
+ LL[[i]] <- LL[[i]]*vec[i]
+ }
> LL
$A
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
$B
[,1] [,2] [,3]
[1,] 2 0
2011 Jul 21
1
replacing duplicate rows
Hi all,
I have a matrix which looks like the following,
x=matrix(c(1,2,3,4,3,5,4,6,4,9),5,2,byrow=T)
Now, I want to replace the 2nd columns of those 4 rows which have duplicate
entries in the 1st column. For example, x[2,1]=x[3,1]=3 and I want to
replace x[3,2] by x[2,2]. Similarly, I want to replace x[5,2] with x[4,2],
which means that for duplicate entries in the 1st column, I want to replace
2007 Mar 30
1
Using split() several times in a row?
Hi, fellow R users.
I have a question about sapply and split combination.
I have a big dataframe (40000 observations, 21 variables). First
variable (factor) is "date" and it is in format "8.29.97", that is, I
have monthly data. Second variable (also factor) has levels 1 to 6
(fractiles 1 to 5 and missing value with code 6). The other 19
variables are numeric.
For each month I
2010 Sep 09
1
executing loop in circular way
Dear all,
I am writing a program using for loop. The loop contains i which runs from
1:n. There is a feature I need to include here. That is, when i=n, i+1 would
be 1, not n+1. Basically the loop should run in a circular fashion. That
also means, if i=1, i-1=n.
Can anyone help me with this? How can I define it?
Thanks.
[[alternative HTML version deleted]]
2011 Feb 14
2
how to overlay a map of US on image plot
Dear all,
I have a data set which has latitude, longitude (not in increasing order)
and observed precipitation corresponding to those locations. I am using
image.plot command for that. But I want to overlay a map of US on that plot.
I know we can use map('usa') to draw it, but I dont know how can I overlay
it on the plot of the precipitation data. Can anyone please help me with it?
2012 Jun 17
3
How to save my result with Loops
Hi everyone, i'm not very good with R, and i know that my question is quite
simple.
I generated this vector for a sample of 100 and i want to know how to save
these as
ez1, ez1, ez3...ez100.
I guess i have to do it by "for", but i didn't succeed..
i put here my output
ezt
[1] -0.05470228 -1.76356668 -1.68843463 -0.77283767 0.25077826
-0.65236833 1.05230056 -0.48900254
2011 Mar 08
1
defining an array with one of the elements being a vector
Dear all,
I am trying to define an array as follows:
a=array(NA,c(m,2,N,G)),
Even though the numbers N and G are fixed, m is a vector. So, I can't define
'a' as above.
For eg,
N=3
G=6,
but m=c(2,7,5) and length(m)=N.
Can anyone suggest me how can I define 'a' when m is a vector?
Thanks in advance for your help.
Cassie
[[alternative HTML version deleted]]
2010 Jul 29
2
Fry Plots
Does anyone know how to do a fry plot in R? I have 600-800 points per image, and I really don't want to attempt that manually.
Thank you!
Cassie
[[alternative HTML version deleted]]
2008 Sep 16
1
Car.proper C[] matrix
I am hoping someone can help translate some WinBUGS code into R code. I
would like to use R to create the C[] matrix required for a car.proper
model in WinBUGS, but I am having a difficult time negotiating the
coding. The C matrix provides normalized weights for each pair of
spatial areas. So the WinBUGS example is as follows:
# of the weight matrix with elements Cij. The first J1 elements
2011 Jul 27
2
for loop help
I am having a hard time putting the below into a loop, where it pulls out ppt from all he stations I have versus having to go through and hard code the data to the specific stations. I tried
stnID <- stnid[which(duplicated(stnid)==FALSE)]
for(i in 1:length(stnID))
{
ppt[i] <- ppt[which(stnid==[i])]
}
but it doesn't like to use the which function inside a for loop? Any idea's here is
2011 May 16
1
simulation from truncated poisson
Dear all,
I need to simulate values from a Poisson distribution which is truncated at
certain value 'a'. Can anyone tell me if there is in-built package in R
which can simulate from a truncated Poisson? If not, what should be the
steps to write a function which would do that?
Thanks in advance.
Cassie
[[alternative HTML version deleted]]
2012 Apr 26
2
problem with break command
Hello R-users,
I am having a problem with the 'break' command in R. I am wondering if
anyone can help me out with this. My program is similar to the following.
a=rep(NA,5)
a[1]=0
for(i in 2:5)
{
a[i]=a[i-1]+runif(1,0,3)
if(a[i]>5)
{
i=2
break
}
}
What exactly I am trying to do is find the sequence 'a' where the
individual values of 'a'
2013 Apr 10
1
problem with the image command
Hello R-users,
I am trying to do an image plot where I have been given latitudes,
longitudes and the values at the corresponding locations. A sample of the
data is given as follows:
values=c(0,1,0,0,0,0,2,2,0,0)
lat=c(29.6660,29.6756,29.3492,29.2654,29.2827,29.4070,35.3510,35.6590,35.7587,38.2794)
2011 Mar 07
1
help needed with histogram plotting
Dear all,
I am trying to plot 3 histograms on the same graph using the following
command.
hist(x,xlim=c(0,100))
hist(y,add=TRUE)
hist(z,add=TRUE)
The xlim of y is c(20,21) and that of z is c(99,99.5) , whereas the variable
x has xlim at c(0.5,2). Apparently, the graph end of displaying a line only,
corresponding to each histogram due to the wide range of the xlim and
tightness of the
2011 Jun 17
1
issue with strptime
Hi everyone,
I have bunch of date and time observations in the format %Y-%m-%d %I %M %S
%p. I used strptime() to read this format. But the problem is some of the
times are in the format of %I %M %p, so for those times, strptime is giving
me NA values.
For example,
strptime(paste("2009-04-08","1:49:47 PM"),format="%Y-%m-%d %I:%M:%S %p")
[1] "2009-04-08
2010 Nov 29
3
Replacing several rows of a matrix at once
Hello Folks. This must be a silly question with a (not) obvious (to me)
answer.
Consider this:
tmp <- matrix(1:200, nrow = 20)
vec <- 300:309
tmp[9,] <- vec # replacing one row works fine
p <- c(3, 11, 17)
tmp[p,] <- vec
# replacing multple rows pastes the values down a column and recycles vec.
What I want to do is replace multiple rows simultaneously at once. I
suppose I can