Displaying 20 results from an estimated 200 matches similar to: "rnorm using vector of means and SDs"
2011 Mar 07
1
Associating the day of week to a daily xts object
I have the following xts objetct "temp"
> str(temp)
An ?xts? object from 2010-12-26 to 2011-03-05 containing:
Data: num [1:70, 1] 2.95 0.852 -0.139 1.347 2.485 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "t_n"
Indexed by objects of class: [POSIXct,POSIXt] TZ: GMT
xts Attributes:
NULL
> temp
t_n
2010-12-26
2008 Oct 05
1
plyr package: passing further arguments fail
Dear list and Hadley,
The new plyr package seems to provide a clean and consistent way to apply a function on several arguments. However, I don't understand why the following example does not work like the standard mapply,
library(plyr)
df <- data.frame(a=1:10 , b=1:10)
foo1 <- function(a, b, cc=0, d=0){
a + b + cc + d
}
mdply(df, foo1, cc=1) # fine
mdply(df, foo1, d=1) #
2011 Aug 20
1
Raw epoch time from XTS
Hi,
I have a very large data set stored as an xts object.
xts is very nice about showing row labels as "human readable" dates and times.
I want the actual epoch values that are stored internally. The only way I can find to access them is one-at-a-time using the internal function: xcoredata()
Calling this in an entire column, the "R" way doesn't work. It will only
2010 Oct 28
1
xyplot and panel.curve
Hi All
I have regression coefficients from an experiment and I want to plot them
in lattice using panel curve but I have run into error messages.
I want an 3 panel conditioned plot of 2 curves of Treatment 2 in each panel
conditioned by Treatment1, the example curve expression is x+value*x^2
A rough toy example to give an idea of what I want is:
Data:
data = expand.grid(Treatment1 =
2010 Nov 12
1
Xapply question
Dear list,
I'm stuck with looking for a function of the *apply family, which I suppose
exists already ? just I can't find it:
What I'm looking for is somewhere between sweep and mapply that does a
calculation vectorized over a matrix and a vector:
It should work complementary to sweep: for each row of the matrix, a different
value of the vector should be handed over.
Close to
2011 Aug 03
1
create a list under constraints
Hi, R users,
Here is an example.
k <- c(1,2,3,4,5)
i <- c(0,1,3,2,1)
if k=1, then i=0
if k=2, then i=0, 1
if k=3, then i=0, 1, 2, 3
if k=4, then i=0, 1, 2
if k=5, then i=0, 1
so i'd like to create a list like below.
> list
k i
1 1 0
2 2 0
3 2 1
4 3 0
5 3 1
6 3 2
7 3 3
8 4 0
9 4 1
10 4 2
11 5 0
12 5 1
I tried expand.grid, but I can't.
Any suggestion will be
2011 May 25
1
Subtracting rows by id
Dear R users,
I have two datasets:
id1 <- c(rep(1,10), rep(2,10), rep(3,10))
value1 <- sample(1:100, 30, replace=TRUE)
dataset1 <- cbind(id1,value1)
id2 <- c(1,2,3)
subtract.value <- c(1,3,5)
dataset2 <- cbind(id2, subtract.value)
I want to subtract the number of rows in the subtract.value that
corresponds to the id value in dataset1. So for the 1 in id1, I want
to
2011 Jun 17
3
rle on large data . . . without a for loop!
I think need to do something like this:
dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000,
replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))
rle.dat<-rle(dat$state)
temp<-1
out<-data.frame(id=1:length(rle.dat$length))
for(i in 1:length(rle.dat$length)){
temp2<-temp+rle.dat$length[[i]]
out$V1[i]<-mean(dat$V1[temp:temp2])
2011 May 24
2
Apply or Tapply to Build Set of Tables
Dear R Helpers,
First, I apologize for asking for help on the first of my topics. I have
been looking at the posts and pages for apply, tapply etc, and I know that
the solution to this must be ridiculously easy, but I just can't seem to
get my brain around it. If I want to produce a set of tables for all the
variables in my data, how can I do that without having to type them into
the table
2011 Oct 22
3
R for loop stops after 4 iterations
I have a data frame called e, dim is 27,3, the first 5 lines look like this:
V1 V2 V3 V4
1 1673 0.36 0.08 Smith
2 167 0.36 0.08 Allen
3 99 0.37 0.06 Allen
4 116 0.38 0.07 Allen
5 95 0.41 0.08 Allen
I am trying to calculate the proportion/percentage of V1 which would have
values >0.42 if V2 was the mean of a normal distribution with V1
2011 Jul 05
3
plotting survival curves (multiple curves on single graph)
Hello.
This is a follow-up to a question I posted last week. With some
previous suggestions from the R-help community, I have been able to
plot survival (, hazard, and density) curves using published data for
Siler hazard parameters from a number of ethnographic populations.
Can the function below be modified, perhaps with a "for" statement, so
that multiple curves (different line
2011 Aug 05
2
Which is more efficient?
Greetings all,
I am curious to know if either of these two sets of code is more efficient?
Example1:
## t-test ##
colA <- temp [ , j ]
colB <- temp [ , k ]
ttr <- t.test ( colA, colB, var.equal=TRUE)
tt_pvalue [ i ] <- ttr$p.value
or
Example2:
tt_pvalue [ i ] <- t.test ( temp[ , j ], temp[ , k ], var.equal=TRUE)
-------------
I have three loops, i, j, k.
One to test the all of
2011 Jun 29
1
Numerical integration
Hello!
I know that probably my question is rather simple but I' m a very beginner
R-user.
I have to numerically integrate the product of two function A(x) and B(x).
The integretion limits are [X*; +inf]
Function A(x) is a pdf function while B(x)=e*x is a linear function whose
value is equal to 0 when the x < X*
Moreover I have to iterate this process for different value of X* and for
2010 Jan 20
2
Please Please Please Help me!!
Dear R helpers
(I have already written the required R code which is giving me correct results for a given single set of data. I just wish to wish to use it for multiple data.)
I have defined a function (as given below) which helps me calculate Macaulay Duration and Modified Duration and its working fine with given set of data.
My Code -
## ONS - PPA
duration = function(par_value,
2004 Apr 18
2
lm with data=(means,sds,ns)
Hi Folks,
I am dealing with data which have been presented as
at each x_i, mean m_i of the y-values at x_i,
sd s_i of the y-values at x_i
number n_i of the y-values at x_i
and I want to linearly regress y on x.
There does not seem to be an option to 'lm' which can
deal with such data directly, though the regression
problem could be algebraically
2009 Jun 25
3
ANOVA with means and SDs as input
Dear R-community,
I'm struggling with a paper that reports only fragmented results of a
2by2by3 experimental design. However, Means and SDs for all cells are given.
Does anyone know a package/function that helps computing an ANOVA with only
Means and SDs as input (resulting in some sort of effect size and
significance test)?
The reason why I'm interested is simple: I'm conducting a
2006 Feb 08
3
difference between rnorm(1000, 0, 1) and running rnorm(500, 0, 1) twice
Hi R users
This looks a simple question
Is there any difference between between rnorm(1000,0,1) and running
rnorm(500,0,1) twice in terms of outcome ?
TM
2000 Mar 07
2
lm(rnorm(1000)~rnorm(1000)) kills rw1000 (PR#476)
First:
R core: (Thank You!)^HUGE_VAL
Now, down to business:
In a loop or in repeated command lines:
system.time(lm(rnorm(1000)~rnorm(1000)))
( or lm(rnorm(1000)~rnorm(1000))$coef )
fails after several iterations with the Windows message 'This program
has performed an illegal operation and will be shut down. If the
problem persists, please contact the vendor'.
clicking on DETAILS
2000 Aug 24
0
distributional properties of rnorm
I've been trying to generate a series of random normal distributions using
the rnorm function. After I generated the first set:
set1<-rnorm(150, 505.5, 15.2)
I checked the mean and standard deviation of set1. I was surprised to find
the mean at 502.37 (rounded) and the standard deviation at 13.3 (again,
rounded). While I know that it is unrealistic to expect the distribution
of the
2000 Aug 24
0
rnorm
Thanks to all who replied to my query about the "normality" of rnorm. I am
using R 1.1.1 (the version released last week) under Windows 98. It has
been unusually hot here and I noticed that the CPU fan seemed to be running
at high speed for a long time. The CPU probe that I use to monitor the
temperature emitted a warning shortly after I sent off the email. After
shutting my