On 2007-July-30 , at 12:20 , Prof Brian Ripley wrote:
> On Mon, 30 Jul 2007, jiho wrote:
>> A recent (in 2.5 I suspect) change in R is giving me trouble. I want
>> to apply a function (tolower) to all the columns of a data.frame and
>> get a data.frame in return.
>> Currently, on a data.frame, bo
On Mon, 30 Jul 2007, jiho wrote:
> Hello everyone,
>
> A recent (in 2.5 I suspect) change in R is giving me trouble. I want
> to apply a function (tolower) to all the columns of a data.frame and
> get a data.frame in return.
> Currently, on a data.frame, both apply (for arrays) and lapply (for
> l
Hello everyone,
A recent (in 2.5 I suspect) change in R is giving me trouble. I want
to apply a function (tolower) to all the columns of a data.frame and
get a data.frame in return.
Currently, on a data.frame, both apply (for arrays) and lapply (for
lists) work, but each returns its native c
- Bruce
-Original Message-
From: Benilton Carvalho [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error
are you positive that your function is doing what
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:43 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error
Then try this:
cor(t(mat1), t(mat2))
Also note
1. the a
TECTED]
> Sent: Tuesday, July 24, 2007 11:31 AM
> To: Bernzweig, Bruce (Consultant)
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] apply & incompatible dimensions error
>
> are you positive that your function is doing what you expect it to do?
>
> it looks like you
t; - Bruce
>
>
> -Original Message-
> From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 24, 2007 11:31 AM
> To: Bernzweig, Bruce (Consultant)
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] apply & incompatible dimensions error
>
> You
uce
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error
Your apply is trying to take the correlations of the
are you positive that your function is doing what you expect it to do?
it looks like you want something like:
sapply(1:10, function(i) cor(mat1[i,], mat2[i,]))
b
On Jul 24, 2007, at 11:05 AM, Bernzweig, Bruce ((Consultant)) wrote:
> Hi,
>
> I've created the following two matrices (mat1 and mat
Your apply is trying to take the correlations of the rows of mat1 with the
columns of mat2 which, of course, does not work if they have different
numbers of columns. I think you mean to take the correlations of the columns
of mat1 with the columns of mat2. For example, to take the correlations
of
Hi,
I've created the following two matrices (mat1 and mat2) and a function
(f) to calculate the correlations between the two on a row by row basis.
mat1 <- matrix(sample(1:500,50), ncol = 5,
dimnames=list(paste("row", 1:10, sep=""),
paste("col", 1:5, sep=
Hi,
first of all, your Scores are factors instead of numeric, you need to change it;
I made a new myDat for test purpose by
myDat = as.data.frame(rbind(myDat, myDat))
myDat[16:30, 3] <- "gene2"
> myDat
tissueScores Grp
a A 3.01494535196933 gene1
b A 2.996476244843
Dear R users,
I have a dataset generated as follows,
myDat <- data.frame(matrix(c(rep(LETTERS[1:3],
each=5),
rnorm(5,mean=3,sd=0.03),
rnorm(5,12,1),
rnorm(5,1,0.5)),
ncol=2,
Hi
[EMAIL PROTECTED] napsal dne 10.05.2007 17:59:22:
> or
>
>with(foo, (x < y) * (x > z))
Should not it be
with(foo, ((x < y) | (x > z))*1)
Regards
Petr
>
> On 5/10/07, jim holtman <[EMAIL PROTECTED]> wrote:
> > You don't need apply. Just do
> >
> > foo$result <- ifelse((foo$x < foo$y
Thank you all for your answers... To summarize,
1. with(X, ifelse(V1 < V2 | V1 > V3, 1, 0))
2. ifelse((foo$x < foo$y) | (foo$x > foo$z), 1, 0)
3. with(foo, (x < y) * (x > z))
were the responses to my question (see below).
Kindly,
Greg
--- Original post ---
> I have
Sorry, you wanted or, not and.
with(foo, pmax(x < y, x > z))
with(foo, as.numeric(x < y | x > z))
with(foo, 1*(x < y | x > z))
On 5/10/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> or
>
> with(foo, (x < y) * (x > z))
>
> On 5/10/07, jim holtman <[EMAIL PROTECTED]> wrote:
> > You don
ifelse(((x < y) | (x > z)), 1, 0)
Note in particular the use of | instead of || for elementwise comparisons.
Petr
Greg Tarpinian napsal(a):
> I have a question that must have a simple answer (but eludes me).
> I need a row-by-row logical comparison across three numeric variables
> in
> a data fr
or
with(foo, (x < y) * (x > z))
On 5/10/07, jim holtman <[EMAIL PROTECTED]> wrote:
> You don't need apply. Just do
>
> foo$result <- ifelse((foo$x < foo$y) | (foo$x > foo$z), 1, 0)
>
> On 5/10/07, Greg Tarpinian <[EMAIL PROTECTED]> wrote:
> > I have a question that must have a simple answer (
Greg Tarpinian wrote:
> I have a question that must have a simple answer (but eludes me).
> I need a row-by-row logical comparison across three numeric variables
> in
> a data frame: foo$x, foo$y, foo$z. The logic is
>
>if( x < y || x > z ) 1 else 0
>
> for a particular row.
>
> It is simpl
You don't need apply. Just do
foo$result <- ifelse((foo$x < foo$y) | (foo$x > foo$z), 1, 0)
On 5/10/07, Greg Tarpinian <[EMAIL PROTECTED]> wrote:
> I have a question that must have a simple answer (but eludes me).
> I need a row-by-row logical comparison across three numeric variables
> in
> a d
I have a question that must have a simple answer (but eludes me).
I need a row-by-row logical comparison across three numeric variables
in
a data frame: foo$x, foo$y, foo$z. The logic is
if( x < y || x > z ) 1 else 0
for a particular row.
It is simple and very inefficient to use for(i in 1:l
aedin culhane <[EMAIL PROTECTED]> writes:
> Dear R-Help
> I am running apply on a data.frame containing factors and numeric
> columns. It appears to convert are columns into as.character? Does it
> convert data.frame into matrix? Is this expected? I wish it to recognise
> numerical columns and
?apply says
If X is not an array but has a dimension attribute, apply attempts to coerce
it to an array via as.matrix if it is two-dimensional (e.g., data frames). .
.
It would probably be easiest with a FOR-LOOP, but you could also try
something like the code below (and insert your operations in
On Fri, 13 Apr 2007, aedin culhane wrote:
> Dear R-Help
> I am running apply on a data.frame containing factors and numeric
> columns. It appears to convert are columns into as.character? Does it
> convert data.frame into matrix? Is this expected? I wish it to recognise
Yes, and quite explicit o
Dear R-Help
I am running apply on a data.frame containing factors and numeric
columns. It appears to convert are columns into as.character? Does it
convert data.frame into matrix? Is this expected? I wish it to recognise
numerical columns and round numbers. Can I use another function instead
On Mar 3, 2007, at 4:28 PM, bunny , lautloscrew.com wrote:
Please use <- for assignments instead of = :
> getans = function(x=qids,bnr=1,type="block")
> {
> #generate name of matrix
> matnam=paste("ans",type,as.character(bnr),sep="")
>
> #display result matrix
> show(assign(matnam,matrix(as
hello,
i have written a function to extract certain lines from a matrix. the
result is a matrix with 6 cols, named dynamically according to the
functions arguments.
the problem is now, that i'm not able to return the resultmatrix for
further use. the object is not being created.
example fro
35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: "Ahn ChaeHyung" <[EMAIL PROTECTED]>
To:
Sent: Tuesday, September 19, 2006 3:32 AM
Su
On Mon, 18 Sep 2006, Ahn ChaeHyung wrote:
> Dear all,
>
> I have the following list, "aa", composed of two 3*3 tables. I would like
> to use "apply" function to summarize it, but "apply" cannot handle "list".
> I want to do it without using any interation.
>
> 1. Is there any function like "
Ahn ChaeHyung wrote:
> Dear all,
>
> I have the following list, "aa", composed of two 3*3 tables. I would like
> to use "apply" function to summarize it, but "apply" cannot handle "list".
> I want to do it without using any interation.
>
> 1. Is there any function like "apply" for list?
> 2.
Dear all,
I have the following list, "aa", composed of two 3*3 tables. I would like
to use "apply" function to summarize it, but "apply" cannot handle "list".
I want to do it without using any interation.
1. Is there any function like "apply" for list?
2. Is there any way to transform that "l
Andy,
Upon further review of the documentation for lars, you are correct.
Thanks for the pointer to the work by Tim et al.
Regards,
Marc
On Fri, 2006-08-18 at 12:48 -0400, Liaw, Andy wrote:
> I believe `lars' does not currently fit glms. For that you'll probably need
> to look at `glar', at:
Any is right.
I don't think current version of lars can be implemented in generalized LM.
On 8/18/06, Liaw, Andy <[EMAIL PROTECTED]> wrote:
> I believe `lars' does not currently fit glms. For that you'll probably need
> to look at `glar', at:
>
> http://www.insightful.com/Hesterberg/glars/defau
I believe `lars' does not currently fit glms. For that you'll probably need
to look at `glar', at:
http://www.insightful.com/Hesterberg/glars/default.asp
HTH,
Andy
From: Marc Schwartz
>
> On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote:
> > Hello list,
> >
> > I've been searching arou
On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote:
> Hello list,
>
> I've been searching around trying to find whether somebody has written such
> a package of least angle regression on generalized linear models, like what
> Lasso2 package does. The extension to generalized linear models is b
Hello list,
I've been searching around trying to find whether somebody has written such
a package of least angle regression on generalized linear models, like what
Lasso2 package does. The extension to generalized linear models is briefly
discussed in the comment by D. Madigan and G. Ridgeway. Is
Maybe this helps
( data1 = list(a=c(1,2), b=c(3,4), c=c(5,6,7)) )
( data2 = list(a=c(10,11), b=c(30,40), c=c(70,80)) )
cc <- NULL
for(data in ls(pattern="^data[0-9]+$")) {
cc <- c(cc, with(get(data), c))
}
mean(cc)
JeeBee.
On Fri, 30 Jun 2006 09:50:51 -0500, Taka Matzmoto wrote:
> Dear R-
Dear R-user
I have 100 lists.
Each list has several components.
For example,
>data1
$a
[1] 1 2
$b
[1] 3 4
$c
[1] 5
There are data1, data2,, data100. All lists have the same number and the
same name of components.
Is there any function I can use for applying to only a specific component
Prof Ripley,
Many thanks for your reply. I did not mean to use apply twice, I meant
to ask about apply and lapply. I understand your comment re: apply. I
assume your comment about lapply is meant to mean that lapply is
implemented in C code and therefore should be faster than a loop written
in R.
On Sun, 14 May 2006, John Sorkin wrote:
> Can someone tell me why apply (and apply) are faster in performing
> repeated operations than a for (or do) loop? I am looking for a
> technical explanation.
apply() is just a wrapper for a for loop. So it is not faster that at
least one implementation
Can someone tell me why apply (and apply) are faster in performing
repeated operations than a for (or do) loop? I am looking for a
technical explanation.
Thanks,
John
John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC and
University of Maryland School of
On Sat, 2006-05-13 at 23:02 +0200, karim.regh wrote:
> Dear Sir,
> Iam a new user of R Software. I thank you very much for this Software.
> By running the R 2.3.0 software I have encountred aproblem:
> I have downloaded the tseriesChaos package from CRAN. When I try to
> run any function of the the
Dear Sir,
Iam a new user of R Software. I thank you very much for this Software.
By running the R 2.3.0 software I have encountred aproblem:
I have downloaded the tseriesChaos package from CRAN. When I try to run any
function of the the tseriesChaos package for example, the c2 function the R
+32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: "Cézar Freitas" <[EMAIL PROTECTED]>
To:
Sent: Wednesday, April 19, 2006 3:50 PM
Subject: [R] apply(table) miss factor structure
Hi, all.
I didn't find something similar to this problem in
past list.
I have a data frame (named restr) where some columns
are factors, like you can see:
> table(restr[,"p1"])
0 1 2 3 4 5
0 26 1 0 1 0
> table(restr[,"p2"])
0 1 2 3 4 5 6
0 13 11 1 2 1 0
When I use appl
apply(cbind(from,to), 1, function(x) sum(g[x[1]:x[2]]))
Fred J. a écrit :
>Dear R users
>
> I am trying to sum selective elements of a vector but my solution
> is not cutting it.
>
> Example:
> > g <- 1:5;
>
> > from <- 1:3;
> > to <- 3:5;
> from to
> 1 3
> 2 4
> 3 5
>
> so
create a matrix and then use apply:
> g <- 1:5;
>
> from <- 1:3;
> to <- 3:5;
>
> index <- cbind(from,to)
> apply(index, 1, function(x) sum(g[x[1]:x[2]]))
[1] 6 9 12
>
On 3/27/06, Fred J. <[EMAIL PROTECTED]> wrote:
>
> Dear R users
>
> I am trying to sum selective elements of a vector but m
Dear R users
I am trying to sum selective elements of a vector but my solution
is not cutting it.
Example:
> g <- 1:5;
> from <- 1:3;
> to <- 3:5;
from to
1 3
2 4
3 5
so I expect 3 sums from g
1+2+3 that is 1 to 3 of g
2+3+4 that is 2 to 4 of g
3+4+5 that
Dear useRs,
shame on me, but I have no idea how to apply two arguments function on
my data. I have 2 vectors, 'n' and 'm' and the function below:
n <- c(10,30,50,1000)
m <- c(10,50,100,200)
MonteCarlo <- function(n,m){
temp <- NULL
for(i in 1:m){
temp <- c(temp,walk(n)) # walk is exter
he business of the statistician is to catalyze the scientific learning
> process." - George E. P. Box
>
>
>
>
>>-Original Message-
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED] On Behalf Of
>>Guenther, Cameron
>>Sent: Friday, January 13, 2006
the statistician is to catalyze the scientific learning
process." - George E. P. Box
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Guenther, Cameron
> Sent: Friday, January 13, 2006 11:03 AM
> To: [EMAIL PROTECTED]
&
Hello,
I have a dataset d which is
>d
pop catch
1 66462.01 10807.757
2 87486.73 46257.885
3 57211.64 9345.058
4 71321.62 4892.868
5 100024.89 27334.248
6 104504.91 48535.092
7 95295.51 39348.195
8 93737.35 34343.489
9 89375.05 28750.743
10 95312.65 30755.0
G'day Robin,
> "RH" == Robin Hankin <[EMAIL PROTECTED]> writes:
RH> How do I rewrite jj() so that it consistently returns a
RH> matrix?
How about explicitly returning a matrix with the desired dimensions?
> jj
function(m1,m2,f,...)
matrix(apply(m1, 1, function(y)
Hi
I am having difficulty with apply(). I want apply() to return a
matrix, but sometimes a vector is returned.
Toy example follows.
Function jj() takes a couple of matrices m1 and m2 as arguments
and returns a matrix with r rows and c columns where r=nrow(m2)
and c=nrow(m1).
jj <- functio
On Thu, 2005-10-13 at 14:50 +0100, Luis Ridao Cruz wrote:
> R-help,
>
> I use the code below to plot some data by applying "apply" function.
> But I don't know how I can get the argument "type" or "col" on the
> "plot" function to distinguish the different lines
> in the graph:
>
> apply ( my.dat
R-help,
I use the code below to plot some data by applying "apply" function.
But I don't know how I can get the argument "type" or "col" on the
"plot" function to distinguish the different lines
in the graph:
apply ( my.data, 2, function ( x ) lines ( dimnames ( my.data ) [[1]] ,
x ) )
Thank yo
> From: Barry Rowlingson
>
> Marc Bernard wrote:
> > Dear All,
> >
> > I wonder how to apply a given function to each row of a
> data frame. I've seen this function before but don't
> remember its name
>
> You've just said it twice!
>
> 'apply'!
A small catch: Marc wants to apply t
Marc Bernard wrote:
> Dear All,
>
> I wonder how to apply a given function to each row of a data frame. I've
> seen this function before but don't remember its name
You've just said it twice!
'apply'!
Baz
__
R-help@stat.math.ethz.ch mailing
Dear All,
I wonder how to apply a given function to each row of a data frame. I've seen
this function before but don't remember its name
Thank you,
Bernard
-
[[alternative HTML version deleted]]
_
On Mon, 25 Jul 2005, Uwe Ligges wrote:
> Laura Holt wrote:
>
>> Hi R!
>>
>> I have a 3 dimensional array, which is 21 x 3 x 3
>>
>> I want to use apply to sum on each 21x3 matrix, which is fine.
>>
>> Is there a way that I can do this in 1 step instead of a loop (3), please?
>
> Don't know which d
Laura Holt wrote:
> Hi R!
>
> I have a 3 dimensional array, which is 21 x 3 x 3
>
> I want to use apply to sum on each 21x3 matrix, which is fine.
>
> Is there a way that I can do this in 1 step instead of a loop (3), please?
Don't know which direction you mean, I guess one of the following:
Hi R!
I have a 3 dimensional array, which is 21 x 3 x 3
I want to use apply to sum on each 21x3 matrix, which is fine.
Is there a way that I can do this in 1 step instead of a loop (3), please?
thanks,
Laura Holt
mailto: [EMAIL PROTECTED]
__
R-help@s
---
From: "Bliese, Paul D LTC USAMH" <[EMAIL PROTECTED]>
To:
Sent: Tuesday, May 31, 2005 10:42 AM
Subject: [R] apply the function "factor" to multiple columns
I have a case where I would like to change multiple columns
containing
numbers to factors. I can change
I have a case where I would like to change multiple columns containing
numbers to factors. I can change each column one at a time as in:
TEMP.FACT$EXPOS01<-factor(TEMP.FACT$EXPOS01,levels=c(1,2,3),labels=c("No
ne","Low Impact","MedHigh Imp"))
TEMP.FACT$EXPOS02<-factor(TEMP.FACT$EXPOS02,levels
On 5/2/05, Christoph Scherber <[EMAIL PROTECTED]> wrote:
> Dear R users,
>
> I´ve got a simple question but somehow I can´t find the solution:
>
> I have a data frame with columns 1-5 containing one set of integer
> values, and columns 6-10 containing another set of integer values.
> Columns 6-10
ven.ac.be/~m0390867/dimitris.htm
- Original Message -
From: "Christoph Scherber" <[EMAIL PROTECTED]>
To:
Sent: Monday, May 02, 2005 4:52 PM
Subject: [R] "apply" question
Dear R users,
I´ve got a simple question but somehow I can´t find the solution:
I have a dat
Try:
> ## Number of NAs in columns 6-10.
> colSums(is.na(data[6:10]))
Col6 Col7 Col8 Col9 Col10
1 1 1 1 0
>
> ## Number of NAs in each row of columns 6-10.
> rowSums(is.na(data[6:10]))
1 2
2 2
>
> ## Sums of rows 1-5 omitting corresponding NAs in cols 6-10.
> rowSums(
- Original Message -
From: "Christoph Scherber" <[EMAIL PROTECTED]>
To:
Sent: Monday, May 02, 2005 10:52 AM
Subject: [R] "apply" question
Dear R users,
I´ve got a simple question but somehow I can´t find the solution:
I have a data frame with columns 1-5 con
Dear R users,
I´ve got a simple question but somehow I can´t find the solution:
I have a data frame with columns 1-5 containing one set of integer
values, and columns 6-10 containing another set of integer values.
Columns 6-10 contain NA´s at some places.
I now want to calculate
(1) the number o
e through
CRAN, you can search on refitting and find it. The original post was from
William Valdar, on April 19.)
Hope this helps,
Matt Wiener
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Christoph Lehmann
Sent: Thursday, April 21, 2005 9:24 AM
To:
4 AM
To: R-help@stat.math.ethz.ch
Subject: [R] apply vs sapply vs loop - lm() call appl(y)ied on array
Dear useRs
(Code of the now mentioned small example is below)
I have 7 * 8 * 9 = 504 series of data (each length 5). For each of
theses series I want to compute a lm(), where the designmatrx
Dear useRs
(Code of the now mentioned small example is below)
I have 7 * 8 * 9 = 504 series of data (each length 5). For each of
theses series I want to compute a lm(), where the designmatrx X is the
same for all these computations.
The 504 series are in an array of dimension d.dim <- c(5, 7, 8,
On 7 Apr 2005 at 14:27, malte wrote:
> Hi,
>
> simple question I guess:
>
> the following line works well:
>
> aveBehav=c(apply(sdata, 2, mean))
Hallo
try
aveBehav=c(apply(sdata, 2, mean, na.rm=T))
Cheers
Petr
>
> However, I would like to pass an argument to the function mean,
> namely n
malte <[EMAIL PROTECTED]> writes:
> aveBehav=c(apply(sdata, 2, mean))
aveBehav= apply(sdata, 2, mean, na.rm=TRUE)
and
?apply will tell you about this.
+ seth
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE
m
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message -
From: "malte" <[EMAIL PROTECTED]>
To:
Sent: Thursday, April 07, 2005 2:27 PM
Subject: [R] apply
Hi,
simple
> From: malte
>
> Hi,
>
> simple question I guess:
>
> the following line works well:
>
> aveBehav=c(apply(sdata, 2, mean))
>
> However, I would like to pass an argument to the function
> mean, namely
> na.rm=TRUE
>
> Does anyone knows how to do this?
aveBehav <- apply(sdata, 2, mean, na.r
On Apr 7, 2005, at 8:27 AM, malte wrote:
Hi,
simple question I guess:
the following line works well:
aveBehav=c(apply(sdata, 2, mean))
However, I would like to pass an argument to the function mean, namely
na.rm=TRUE
apply(sdata,2,function(x) {mean(x,na.rm=TRUE)})
Sean
___
Hi,
simple question I guess:
the following line works well:
aveBehav=c(apply(sdata, 2, mean))
However, I would like to pass an argument to the function mean, namely
na.rm=TRUE
Does anyone knows how to do this?
Thanks in advance,
Jan
__
R-help@stat.math.
: [R] apply a function to a rolling subset of a vector
Whit Armstrong wrote:
>Does anyone know an easy way to calculate the rolling 20 period average
>or sum of a vector?
>
>For instance:
>x <- rnorm(1000)
>
>y <- apply.subset(x,20,fun="sum")
>
>
hel
Whit Armstrong twinfieldscapital.com> writes:
:
: Does anyone know an easy way to calculate the rolling 20 period average
: or sum of a vector?
:
: For instance:
: x <- rnorm(1000)
:
: y <- apply.subset(x,20,fun="sum")
:
: The first element of y would contain the sum of elements 1 to 20, the
On Wed, 2005-03-02 at 17:22 -0500, Whit Armstrong wrote:
> Does anyone know an easy way to calculate the rolling 20 period average
> or sum of a vector?
>
> For instance:
> x <- rnorm(1000)
>
> y <- apply.subset(x,20,fun="sum")
>
> The first element of y would contain the sum of elements 1 to 20
On Wed, 2 Mar 2005 17:22:43 -0500, "Whit Armstrong"
<[EMAIL PROTECTED]> wrote :
>Does anyone know an easy way to calculate the rolling 20 period average
>or sum of a vector?
>
>For instance:
>x <- rnorm(1000)
>
>y <- apply.subset(x,20,fun="sum")
>
>The first element of y would contain the sum of e
Try this:
> ?convolve
> x<-rnorm(1000)
> y<-rep(1,20)
> z<-convolve(x,y,type="filter")
> plot(x,type="l")
> str(z)
num [1:981] 6.31 7.28 8.16 7.39 4.65 ...
> lines(c(rep(0,10),z,rep(0,10)),col="yellow",lwd=3)
> lines(c(rep(0,10),z,rep(0,10))/length(y),col="red",lwd=3) #running mean
You wrote:
Do
Does anyone know an easy way to calculate the rolling 20 period average
or sum of a vector?
For instance:
x <- rnorm(1000)
y <- apply.subset(x,20,fun="sum")
The first element of y would contain the sum of elements 1 to 20, the
second element of y
would contain the sum of elements 2:21, and so o
Actually, what you want is sapply.
sapply(tst.list, "[[", "VAL")
Kevin
Alexandre Sanchez Pla wrote:
Hi,
I am working with lists whose terms are lists whose terms are lists. Although
the real ones contain locuslink identifiers and GO annotations (I work with the
Bioconductor GO) package, I have pr
Alexandre Sanchez Pla ub.edu> writes:
:
: Hi,
:
: I am working with lists whose terms are lists whose terms are lists.
Although
: the real ones contain locuslink identifiers and GO annotations (I work with
the
: Bioconductor GO) package, I have prepared an simplified example of what I
have
[EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Alexandre Sanchez Pla
> Sent: Wednesday, January 26, 2005 8:50 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] apply for nested lists
>
> Hi,
>
> I am working with lists whose terms are lists whose terms are
Here's one (not so general) way:
> x <- unlist(tst.list)
> x[grep("VAL", names(x))]
1.1A.VAL 1.1B.VAL 1.1C.VAL 3.3A.VAL 3.3B.VAL
"172""134" "0" "33" "2"
Do you need the NA?
Andy
> From: Alexandre Sanchez Pla
>
> Hi,
>
> I am working with lists whose terms are lists whos
Hi,
I am working with lists whose terms are lists whose terms are lists. Although
the real ones contain locuslink identifiers and GO annotations (I work with the
Bioconductor GO) package, I have prepared an simplified example of what I have
and what I would like to do with it:
Imagine I have a
Eric Pellegrini <[EMAIL PROTECTED]> writes:
> Hi all,
>
> I have a question about apply function. Is that possible to pass some
> non-default arguments in the function we want to apply ?
>
> For example:
>
> if "mat" is a matrix and I want to use the "tabulate" function on its row.
>
> The co
Try apply(mat, 1, tabulate, nbins=4).
HTH,
Andy
> From: Eric Pellegrini
>
> Hi all,
>
> I have a question about apply function. Is that possible to pass some
> non-default arguments in the function we want to apply ?
>
> For example:
>
> if "mat" is a matrix and I want to use the "tabulate"
you seem to need
apply(mat, 1, tabulate, nbins=4)
isnt it?
Stefano
-Messaggio originale-
Da: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] conto di Eric Pellegrini
Inviato: mercoledì 20 ottobre 2004 18.54
A: [EMAIL PROTECTED]
Oggetto: [R] apply function
Hi all,
I have a question about
Hi all,
I have a question about apply function. Is that possible to pass some
non-default arguments in the function we want to apply ?
For example:
if "mat" is a matrix and I want to use the "tabulate" function on its row.
The command apply(mat,1,tabulate) works but I have problem with this on
apply() tries to be a bit smart about what it does (sometimes maybe too
smart), but it actually is pretty useful a lot of the time. It's extremely
widely used, so changing the behavior is not an option -- changing the
behavior would break a lot of existing code. (Personally, I'd prefer it if
a <- matrix (c(
7, 1, 1, 2, 6,
3, 4, 0, 1, 4,
5, 1, 8, 4, 4,
6, 1, 1, 2, 5), nrow=4, byrow=TRUE)
b <- apply (a, 1, table)
"apply" documentation says clearly that if the rows of the result of FUN
are the same length, then an array will be returned. And column-major
would be th
Whoops!
Just found it:
by(iris[,1:4],Species,mean)
Sorry for the inconvenience.
Laura.
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the p
Hi R People:
There are 2 data sets of the iris data: one is iris3, which is a 3-d array,
and the other is iris, which
is a data frame with 150 rows and 6 variables.
Getting means is straightforward from the 3-day iris3 set:
apply(iris3,c(2,3),mean)
Setosa Versicolor Virginica
Sepal L. 5.
Laura Quinn wrote:
x=1:2881
my.new.matrix<-matrix(nrow=2881,ncol=20)
for(i in 1:20){
my.new.matrix[[i]]<-approx(x,my.matrix[,i],n=2881)
}
the error message says:
Error: more elements supplied than there are to replace
where am I going wrong??
approx() returns a list with $x and $y components
I'd us
I have several large matrices each having perhaps one or two
data points missing. For instance one point in 2881 is missing. As I want to perform
various analyses on these matrices I feel it is not
unreasonable to linearly interpolate over the missing points. I want to basically
"fill in
the gaps"
Subject: RE: [R] Apply a function to each cell of a ragged matrix
rowsum(x,f)
---
Date: Tue, 17 Feb 2004 17:38:46 -0500
From: XIAO LIU <[EMAIL PROTECTED]>
To: R Help <[EMAIL PROTECTED]>
Subject: [R] Apply a function to each cell of a ragged matrix
R-Helpers:
There are a m
1 - 100 of 128 matches
Mail list logo