Displaying 20 results from an estimated 200 matches similar to: "Xapply question"
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) #
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 =
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
2010 Sep 14
3
rnorm using vector of means and SDs
Hi,
I want to sample from a distribution (say a normal distribution, for example) using vectors of the different parameters (i.e. the mean and standard deviation). That is, I have a list/vector of say 100 means and another of the corresponding 100 SD's, and I want a matrix of 100 rows (one for each mean and SD pair) each having 1000 random samples.
Something like:
sample_matrix =
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,
2008 Nov 12
2
Outer, kronecker, etc.
`outer` (and related functions like kronecker) require that their
functional argument operate elementwise on arrays. This means for
example that
outer( 1:2, 3:4, list)
or
outer(1:2,3:4,function(a,b){1})
gives an error.
Is there a version of `outer`/`kronecker`/etc. that takes arbitrary
functions and does its own elementwise mapping? In the first example
above, I'd expect the
2009 Dec 19
4
expand.grid game
Dear list,
In a little numbers game, I've hit a performance snag and I'm not sure
how to code this in C.
The game is the following: how many 8-digit numbers have the sum of
their digits equal to 17?
The brute-force answer could be:
maxi <- 9 # digits from 0 to 9
N <- 5 # 8 is too large
test <- 17 # for example's sake
sum(rowSums(do.call(expand.grid, c(list(1:maxi),
2011 Jan 20
4
puzzled with plotmath II
sorry, I forgot my sessionInfo: please see below.
-------- Original Message --------
Subject: puzzled with plotmath
Date: Thu, 20 Jan 2011 12:48:18 +0100
From: Claudia Beleites <cbeleites at units.it>
To: R Help <r-help at r-project.org>
Dear all,
I'm puzzled with matrix indices in plotmath.
I'm plotting matrix elements: Z [i, i], and I'd like to put that as label.
2023 Aug 10
2
Expresión en un objeto
Hola a todos:
Se me ha planteado un problema que no está ligado a ningún problema
concreto. Es más teórico.
Supongamos que tenemos tres variables:
V1 <- c (47, 71, 41, 23, 83, 152, 82, 8, 160, 18)
V2a <- c (NA, 36, 15, 5, 56, 18, NA, 5, NA, 5)
V2b <- c (37, NA, 15, NA, NA, NA, 90, NA, 161, NA)
Supongamos que tengo la expresión (que no puedo asignarlo a
2010 Nov 10
2
force apply not to drop the dimensions of FUN results ?
Dear R users,
Here is my problem:
I have an array with at least four dimensions:
> dim(myArray)
[1] 20 17 3 6
I'd like to apply a function to each occurrence of the matrix (3x6)
defined by the last two dimensions. This interpolation function always
return a matrix of the same dimensions as its argument:
> interpSecteurs.f(myArray[1, 1, , ])
secteur
rotation 1 2 3
2008 Nov 03
1
Fourier Transform with irregularly spaced x
Dear all,
I work with (vibrational) spectra: some kind of intensity (I) over frequency
(nu), wavelength or the like.
I want to do fourier transform for interpolation, smoothing, etc.
My problem is that the spectra are often irregularly spaced in nu: the
difference between 2 neighbouring nu varies across the spectrum, and data
points may be missing.
Searching for discrete fourier transform
2008 Dec 12
0
Fwd: Re: The end of Matlab (sorry, I messed up a sentence)
---------- Weitergeleitete Nachricht ----------
Betreff: Re: [R] The end of Matlab
Datum: Freitag 12 Dezember 2008
Von: Claudia Beleites <cbeleites at units.it>
An: r-help at r-project.org
Am Freitag 12 Dezember 2008 13:10:20 schrieb Patrick Burns:
> How about:
>
> x[, -seq(to=ncol(x), length=n)]
Doing it is not my problem. I just agree with Mike in that I would like if I
could
2023 Aug 11
1
Expresión en un objeto
A ver... con que xfunc() esté preparada para tomar un parámetro de tipo "carácter" y evaluarlo, claro que se puede hacer...
Si el problema lo tienes en evaluar la expresión, la función "eval()" te lo hace.
Si no te he entendido bien, explícate más ?
Saludos
Isidro
-----Mensaje original-----
De: R-help-es <r-help-es-bounces en r-project.org> En nombre de Griera
Enviado