Displaying 20 results from an estimated 10000 matches similar to: "R: simulation"
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 Dec 23
2
R-way to doing this?
Dear friends, hope I could be able to explain my problem through following
example. Please consider this:
> set.seed(1)
> input <- rnorm(10)
> input
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684
0.4874291 0.7383247 0.5757814 -0.3053884
> tag <- vector(length=10)
for(i in 1:10)
# if there is any ****error**** in evaluating
2011 Jun 06
2
A Calculation on list object
Hello, I am into some calculation on a list object, therefore requesting the peers if there is any short cut way to so the same calculation.
Let say I have following list object:
> List <- vector('list', length = 3)
> set.seed(1)
> List[[1]] <- rnorm(5)
> List[[2]] <- rnorm(2)
> List[[3]] <- rnorm(7)
> List
[[1]]
[1] -0.6264538 0.1836433 -0.8356286
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
2009 Jun 11
2
How to force R to print 2 decimal places in column of a data.frame?
How to force R to print 2 decimal places in column of a data.frame? I tried to do so:
x = inp(format(rounf(inp$Tamanho, 2), nsmall = 2),)
where "INP" is data.frame and "Size" is the name of column. But has error:
Error in eval.with.vis(expr, envir, enclos) :
could not find function "inp"
Lesandro
Veja quais s?o os assuntos do momento no Yahoo! +Buscados
2011 Jul 16
2
(unclassified?) Help Question
Dear List,
I'd appreciate you guidance for obtaining the desired result shown
below, by combining tapply(x, g, mean) and g in the example.
Basically, I'm trying to create a vector whose values are based on the
result from tapply(x, g, mean) but that follow the pattern and length
given by the factor g. Of course I'm looking for a generic solution
(i.e, not something that just work
2009 Jul 01
5
convert tabular time series into a matrix format
Hi, thanks everyone for any help in advance.
I found myself dealing with a tabular time-series data formatted each row
like [ time stamp, ID, values]. I made a small examples:
X = data.frame(t=c(1,1,1,2,2,2,2,3,3,3,4,4,4,5,5),id =
2011 Jan 25
1
NA printing
Hi.
I'm writing a print method for an object that includes a numeric matrix
for which
the lower diagonal elements are not meaningful. So I make the lower
diagonal of my matrix NA and print it.
But my co-author does not like NA there and wants a dash.
I have tried coercing the matrix to character, essentially by
M[is.na(M)] <- "-" but this interferes with the pleasing
column
2008 May 09
2
which.max2()
Hello,
which.max() only returns one index value, the one for the
maximum value. If I want the two index values for the two
largest values, is this a decent solution, or is there a
nicer/better R'ish way?
max2 <-function(v)
{
m=which.max(v)
v[m] = -v[m]
m2=which.max(v)
result=c(m, m2)
result
}
Seems to work ok.
Thanks,
Esmail
2006 Oct 02
1
CCF and ACF
Dear all,
given two numeric vectors x and y, the ACF(x) at lag k is
cor(x(t),x(t+k)) while the CCF(x,y) at lag k is cor(x(t),y(t-k)). See
below for a simple example.
> set.seed(1)
> x <- rnorm(10)
> y <- rnorm(10)
> x
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684
0.4874291 0.7383247 0.5757814 -0.3053884
> y
[1] 1.51178117 0.38984324
2005 Mar 01
6
Help : delete at random
Hello
I would like to delete some values at random in a data frame. Does
anyone know how I could do?
With best regards
Caroline
2009 Jun 22
2
Help on creating a sequence of vectors
I want to create a number of vectors like :
vec1 <- rnorm(1)
vec2 <- rnorm(2)
vec3 <- rnorm(3)
and so on...........
Here I tried following :
for (i in 1:10) paste("vec", i, sep="") <- rnorm(i)
However obviously that is not working. Here vectors I need to be seperated
i.e I do not want to create a "list". How to modify above code?
--
View this
2004 Aug 13
1
How to use the whole dataset (including between events) in Cox model (time-varying covariates) ?
Hello,
coxph does not use any information that are in the dataset between event
times (or "death times") , since computation only occurs at event times.
For instance, removing observations when there is no event at that time in
the whole dataset does not change the results:
> set.seed(1)
> data <-
as.data.frame(cbind(start=c(1:5,1:5,1:4),stop=c(2:6,2:6,2:5),status=c(rep(
2005 Sep 30
4
by() processing on a dataframe
I want to calculate a statistic on a number of subgroups of a dataframe,
then put the results into a dataframe. (What SAS PROC MEANS does, I
think, though it's been years since I used it.)
This is possible using by(), but it seems cumbersome and fragile. Is
there a more straightforward way than this?
Here's a simple example showing my current strategy:
> dataset <-
2010 May 13
3
select subset based on another variable
Hi, dear R-helpers,
I have a simple question regarding selecting subset of a variable based on
another variable.
Here is the example:
xx=rnorm(10)
id=sample(1:10, 10)
temp=c(6, 1, 8, 2)
Now, all I want is xx's that their id are 6, 1, 8, 2, instead of the
position.
Any suggestions ?
Thank you all your help !!
Carrie
[[alternative HTML version deleted]]
2011 Feb 02
0
How column names/row names are preserved in matrix calculation?
Can somebody tell me that, if I do some arithmetic calculation over 2
matrices then how the column names and row names are preserved? It seems
that, for multiplication, column names and row names of the 2nd matrix are
preserved and for additional, there seems not having any explicit rule:
> set.seed(1)
> dat1 <- matrix(rnorm(25), 5); colnames(dat1) = rownames(dat1) =
2004 Sep 29
3
R: string connections
hi all
i have a simple question:
lets assume that i can enter a variable (a) equal to some value, say
100. obviously a could be any value. i would like to create a plot with
a main heading as
hi all
"some writing" + a
how would own create a string by combining a string with a numeric
variable?
hope the question is not too confusing.
e.g. say a=5 then i want something like
2004 Feb 10
6
R: lags
hi all
how does one simulate a random walk process?
i.e
y(0)=0
y(t)=y(t-1)+ e(t)
where e(t) is normal(0,1) say.
Regards
allan
2005 Sep 15
2
R: deleting rows
hi all
hopefully some one can help.
assume that i imported the following data into R (say the data frame is
called a)
x1 x2 x3
1 NA 3
1 2 NA
1 2 3
3 NA 6
4 5 9
7 5 6
7 8 9
NA 7 9
How can i construct a new data frame that only contains those rows that
does not contain the NA's? is these a quick way?
ie
x1 x2 x3
1 2 3
4 5 9
7 5 6
7 8 9
in this example we can simple use
2005 Jul 29
5
R: graphics devices
a simple question
how does one produce plots on two different graphics devices?
/
allan