The calculation appears to be sum(a)/(sum(a)+sum(b)).
library(dplyr)
library(tidyr)
result <- ( this_df
%>% gather( group, truth, -c(a,b) )
%>% group_by( group, truth )
%>% summarise( calc = sum(a)/(sum(a)+sum(b)) )
%>% as.data.frame
)
-
Hello all,
I've been banging my head over what must be a simple solution. I would
like to apply a function across columns of a dataframe for rows grouped
across different columns. These groups are not exclusive. See below
for an example. Happy to use dplyr, data.table, or whatever. Any
g
Hello,
Please cc the list, the odds of getting more and better answers are greater.
And you should tell us from what package do the function plot.correlog
comes. library(what)?
As for your question, assuming you want to save your plots as PNG files,
you could do something like the following.
> Le 24 oct. 2014 à 09:23, Sarah a écrit :
>
> Thank you very much, it helped a lot!
>
> I just have another question know. I want to make plot for every species. I
> just add the function « plot correlog » to the previous function and I have
> now the following script:
>
> ddeg.correlog.li
Hello,
Yes, you can use lapply. Maybe something like the following. Note that
the result is a list with one member per species. (Untested).
ddeg.correlog.list <- lapply(9:11, function(p)
correlog(plant[plant[,p]=="1", 2], plant[plant[,p]=="1", 3],
plant[plant[,p]=="1", 4]))
Hope this help
Hello List,
I have a database which consist of 912 plots. For each plot, I have the
presence/absence information of 260 species of plants and also 5 different
environmental variables (ddeg, mind, srad, slp, topo).
The dataframe looks like this:
Plot_NumberX Y ddeg mi
Hello,
Have you tried
mapply(f, list_df, list_par, MoreArgs = list(z = fix), SIMPLIFY = FALSE)
?
Hope this helps,
Rui Barradas
Em 14-10-2014 19:42, Carlos Nasher escreveu:
Hi R helpers,
I'm struggling how to apply a function to multiple lists. My function uses
a dataframe, a list of param
Hi R helpers,
I'm struggling how to apply a function to multiple lists. My function uses
a dataframe, a list of parameters and a fixed value as arguments. Now I
want to apply that function to several dataframes contained in list, with
several lists of parameters (also contained in a list) and the
Hi,
Try:
indx <- grep("Test",test_df[,1]) ##assuming that there is some pattern
res <- within(test_df[-indx,],titel <- rep(test_df$titel[indx],
diff(c(indx,nrow(test_df)+1))-1))
## If you need to change the class
res[] <- lapply(res,function(x) if(any(grepl("[[:alpha:]]",x)))
as.character(x) e
Hi,
Try:
indx <- grep("Test",test_df[,1]) ##assuming that there is some pattern
res <- within(test_df[-indx,],titel <- rep(test_df$titel[indx],
diff(c(indx,nrow(test_df)+1))-1))
## If you need to change the class
res[] <- lapply(res,function(x) if(any(grepl("[[:alpha:]]",x))) as.character(x)
This might be of some use :
http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/
Umair Durrani
email: umairdurr...@outlook.com
> Date: Sat, 16 Nov 2013 07:30:29 -0800
> From: ron...@gmx.net
> To: r-help@r-project.org
> Subject: [R] Apply function to
Hi guys, I am a total newbie to R, so I hope this isn't a totally dumb
question. I have a dataframe with a title in one row and the corresponding
values in the next rows. Let's take this example:
test_df <- data.frame(cbind(titel = "", x = 4:5, y = 1:2))
test_df = rbind(cbind(titel="1.Test", x=""
HI,
set.seed(25)
dat1 <-
as.data.frame(matrix(sample(c("A","T","G","C"),46482*56,replace=TRUE),ncol=56,nrow=46482),stringsAsFactors=FALSE)
lst1 <- split(dat1,as.character(gl(nrow(dat1),20,nrow(dat1
res <- lapply(lst1,function(x) sapply(x[,1:8],function(y) sapply(x[,9:56],
function(z)
Hi,
May be this what you wanted.
res2 <- lapply(row.names(res[[1]]),function(x)
do.call(rbind,lapply(res,function(y) y[match(x, row.names(y)),])))
length(res2)
#[1] 48
dim(res2[[1]])
#[1] 2325 8
A.K.
On Monday, November 11, 2013 10:20 PM, Yu-yu Ren wrote:
Thank you so much for that scr
HI,
It's not very clear.
set.seed(25)
dat1 <-
as.data.frame(matrix(sample(c("A","T","G","C"),46482*56,replace=TRUE),ncol=56,nrow=46482),stringsAsFactors=FALSE)
lst1 <- split(dat1,as.character(gl(nrow(dat1),20,nrow(dat1
res <- lapply(lst1,function(x) sapply(x[,1:8],function(y) sapply(x[,9:56]
0342 0.5567617 0.3721136 0.4480448
A.K.
- Original Message -
From: Amanda Li
To: r-help@r-project.org
Cc:
Sent: Monday, September 30, 2013 10:55 AM
Subject: [R] Apply function to do pairwise calculation
Hello,
I want to do pairwise calculation, but I am not sure how to do so.
i.e. I h
Amanda,
If I understand what you're trying to do, this example might help you.
M <- structure(c(0.66, 0.05, -0.93, -0.61, 0.65, -0.25, 0.23, -0.89,
0.37, 0.38, -0.91, 0.91, -0.05, -0.65, -0.94, 0.73, -0.88, 0.25,
0.04, -0.89, -0.47, -0.46, 0.86, -0.29, 0.92, 0.22, 0.77, -0.98,
-0.56, 0.11, 0.35
Hello,
I want to do pairwise calculation, but I am not sure how to do so.
i.e. I have a correlation matrix M 200*200. Namely colnames(M)=rownames(M).
In addition, colnames(M) is one of A, B, C, D. I want to first sort the
matrix M into 16 modules according to colnames and rownames, and then apply
#5 group3 6 e 500 500
#6 group4 7 f 600 NA
A.K.
From: Estefanía Gómez Galimberti
To: arun
Cc: R help
Sent: Thursday, May 23, 2013 12:08 PM
Subject: Re: [R] apply function within different groups
Thanks a lot!!! It works perkectly!
Just
group4 7 f 600 NA
A.K.
From: Estefanía Gómez Galimberti
To: arun
Cc: R help
Sent: Thursday, May 23, 2013 12:08 PM
Subject: Re: [R] apply function within different groups
Thanks a lot!!! It works perkectly!
Just one thing, is there a way to prese
Galimberti
Cc: R help
Sent: Thursday, May 23, 2013 12:48 PM
Subject: Re: [R] apply function within different groups
Hi,
May be this helps:
dat1<- read.table(text="
group var1 var2 myvar
group1 1 a 100
group2 2 b 200
group2 34 c 300
group3 5 d 400
group3 6 e 500
group4 7 f 600
",
)
# group f_myvar
#1 group1 NA
#2 group2 299
#3 group2 300
#4 group3 499
#5 group3 500
#6 group4 NA
A.K.
- Original Message -
From: Estefanía Gómez Galimberti
To: r help help
Cc:
Sent: Thursday, May 23, 2013 11:30 AM
Subject: [R] apply function within dif
Hi,
I have a very big data frame and I would like to apply a function to one of the
columns within different groups and obtain another dataframe
My data frame is like this:
group var1 var2 myvar
group1 1 a 100
group2 2 b 200
group2 34 c 300
group3 5 d 400
group3 6 e 500
group4 7 f 600
Excellent, thank you to both of you!!!
Gail
--
View this message in context:
http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638681p4639009.html
Sent from the R help mailing list archive at Nabble.com.
__
R-h
Thanks Elk,
That was the missing link.
#or
lapply(list6,function(x)max(x$target))
[[1]]
[1] 6
[[2]]
[1] 18
[[3]]
[1] 9
max(unlist(lapply(list6,function(x) max(x$target
A.K.
___
If you reply to this email, your message will be added to the disc
Hi Arun,
if you name the data.frame in the list, e.g.
mango <- list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9),
nn=paste0("a",1:6),target=data.frame(coconut=1:6))
banana <- list(target=data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1),
bw=c(4,18,22,3,4), nn=paste0("a",1:5))
pineapple <- list(target=d
Hi Elk,
I tried to test with another case where coconut is in different position in
the sublist.
mango <- list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9),
nn=paste0("a",1:6),data.frame(coconut=1:6))
banana <- list(data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1),
bw=c(4,18,22,3,4), nn=paste0("a",1:
Hello,
I was in a hurry at the time, when I replied.
You could do one thing: extract sublist using:
list4 <- list(mango, banana, pineapple)
b1<-list()
for(i in 1:3){
b1[[i]]<-list()
b1[[i]]<-list4[[i]][1]
}
b1
b<-list()
for(i in 1:3){
b[[i]]<-list()
b[[i]]<-lapply(b1[[i]][[1]],FUN=functio
Hi Elk,
Thanks for the input. Somehow, I got entangled with which.max. I should
have used max.
lapply(list4,function(x) max(x[[1]]$coconut))
[[1]]
[1] 6
[[2]]
[1] 18
[[3]]
[1] 9
max(unlist(lapply(list4,function(x) max(x[[1]]$coconut
#[1] 18
A.K.
I still try to figure out, what you are finally asking for, but maybe
res<-sapply(list4,function(x)max(x[[1]]$coconut))
names(res)<-c("mango", "banana", "pineapple")
res
max(res)
is worth a try?
Especially i did not get the point of doing something like
x[which.max(x)] because this is in any cas
Hello,
If I understand it now, can't you do this:
Individual cases:
list4<-list(mango[[1]],banana[[1]],pineapple[[1]])
b<-list()
for(i in 1:3){
b[[i]]<-list()
b[[i]]<-lapply(list4[[i]],FUN=function(x)x[which.max(x)])
}
b1<-data.frame(do.call(rbind,b))
row.names(b1)<-c("mango","banana","pineap
Hi,
my dataset is the result of the function "density" on another set of data.
It refers to that data in its variable "call", though since all the results
are actually reproduced (except that I've removed all rows bar 10), I am not
sure why R still needs it. But I've understood now why your code d
Michael, here is the data I am working with. I've shortened it without, I
trust, changing its nature. I am not using any package other than what is
pre-installed. Many thanks, Gail
> dput(list.example)
list
(structure(list(
x = c(379.455895016957, 380.116796110287,
380.777697203618, 381.438598
Well but the whole point was to be able to plug in a single command and get
the result for all sublists. If I have to create a new list and type in each
sublist and the column I'm interested in, that completely defeats the
purpose, I might as well just ask for max(sublist$coconut) for each sublist,
Arun, I see you've defined dat5 in your later message; however the same
applies as to the above: the code doesn't work if the list contains
non-numerical elements.
Gail
--
View this message in context:
http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638
Hi,
I am not able to read your dataset.
Getting errors.
source("list1.txt")
Error in paste(locuteur, i, sep = "") : object 'locuteur' not found
Please check.
A.K.
__
If you reply to this email, your message will be added to the discussion below:
http://r.7896
Hello Gail,
The dat5 was in earlier post. I forgot to paste it.
Now, your question regarding individual cases,
This is a case that includes nonnumeric columns
list1<-list(data.frame(x=1:6,y=c(4,5,3,2,1,8),bw=c(4,18,12,3,4,9),nn=paste0("a",1:6)))
list2<-list(data.frame(x=c(1,2,18,16,15),y=c(4,5,9,
HI,
I tested the code for another set of data with added complexity. Seems to
be working fine.
list1<-list(data.frame(x=1:6,y=c(4,5,3,2,1,8),bw=c(4,18,12,3,4,9)))
list2<-list(data.frame(x=c(1,2,18,16,15),y=c(4,5,9,2,1),bw=c(4,18,22,3,4)))
list3<-list(data.frame(x=c(4,6,9),y=c(8,24,12),bw=c(14,31,3
I'm a little confused on your data structure -- can you use dput() as
described here [1] to give a small reproducible example?
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
Michael
On Wed, Aug 1, 2012 at 10:38 AM, gail wrote:
> Thank you!!! But I realise
On Wed, Aug 1, 2012 at 8:43 AM, gail wrote:
> Hello. Please forgive me if this problem has already been posted (and solved)
> by someone else ... I can't find it anywhere though it seems so very basic.
> Here it is:
>
> I have a list comprised of several matrices, each of which has two columns.
>
Thank you!!! But I realise I've simplified my data to the point that your
solution doesn't actually work -- not your fault, mine! My list is actually
more complicated than what I presented it to be; it's not composed of
numerical matrices but of lists, each being composed of 7 columns, the first
tw
Hello. Please forgive me if this problem has already been posted (and solved)
by someone else ... I can't find it anywhere though it seems so very basic.
Here it is:
I have a list comprised of several matrices, each of which has two columns.
> list
[[1]]
[,1] [,2]
[1,]1 3
[2,]
FYI below.
On Fri, Jun 22, 2012 at 4:00 PM, Luba G wrote:
> Thanks Rui!
> I was not aware that *number*L is an alternate to as.integer(*number*).
> Luba
>
> > identical(2,as.integer(2))
[1] FALSE
> identical(2L,as.integer(2))
[1] TRUE
Cheers,
Bert
> On Fri, Jun 22, 2012 at 3:53 PM, Rui Barra
Thanks Rui!
I was not aware that *number*L is an alternate to as.integer(*number*).
Luba
On Fri, Jun 22, 2012 at 3:53 PM, Rui Barradas wrote:
> Hello,
>
> 2L is an integer, 2 might be or not. In the case of apply(), there is no
> difference.
>
> All possible values for margin? Any possible(*) co
Right, I had missed that one.
To the op: what Michael is saying can be shown with the following example.
x <- array(1:24, c(2,3,4))
r1 <- apply(x, -1, sum) # remove dim 1
r2 <- apply(x, 2:3, sum) # include dims 2 and 3
all.equal(r1, r2) # FALSE, different attributes
all(r1 == r2) # TRUE, eq
On Fri, Jun 22, 2012 at 5:53 PM, Rui Barradas wrote:
> Hello,
>
> 2L is an integer, 2 might be or not. In the case of apply(), there is no
> difference.
>
> All possible values for margin? Any possible(*) combination of the
> dimensions of 'x' in
>
> apply(x, margin, function)
>
> (*) non-null. If
Hello,
2L is an integer, 2 might be or not. In the case of apply(), there is no
difference.
All possible values for margin? Any possible(*) combination of the
dimensions of 'x' in
apply(x, margin, function)
(*) non-null. If, say, x <- array(0, dim=c(2,3,4)) (3dim) then you can
call any of
What is the difference of using 2L versus 2 as the margin argument in the
apply() function? Where can I find detailed information on all of the
possible margin arguments?
> x
[,1] [,2]
[1,]12
[2,]34
[3,]56
[4,]78
[5,]9 10
> sqrt(apply(x, *2L*, function(r.
Thank you very much for your comments Ista and David! I will
experiment and see which one serves my needs best.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/po
On Apr 5, 2012, at 7:01 AM, Michael Bach wrote:
Dear R users,
how do I e.g. square each second element of a vector with an even
number of elements? Or more generally to apply a function to every
'nth' element of a vector. I looked into the apply functions, but
found no hint.
For example:
v <
ken knoblauch inserm.fr> writes:
>
> Michael Bach gmail.com> writes:
> > how do I e.g. square each second element of a
> vector with an even
> > number of elements? Or more generally to
> apply a function to every
> > 'nth' element of a vector. I looked into the
> apply functions, but
> > fo
Michael Bach gmail.com> writes:
> how do I e.g. square each second element of a
vector with an even
> number of elements? Or more generally to
apply a function to every
> 'nth' element of a vector. I looked into the
apply functions, but
> found no hint.
> For example:
> v <- c(1, 2, 3, 4)
> mys
Good morning Michael,
On Thu, Apr 5, 2012 at 7:01 AM, Michael Bach wrote:
> Dear R users,
>
> how do I e.g. square each second element of a vector with an even
> number of elements? Or more generally to apply a function to every
> 'nth' element of a vector. I looked into the apply functions, but
Dear R users,
how do I e.g. square each second element of a vector with an even
number of elements? Or more generally to apply a function to every
'nth' element of a vector. I looked into the apply functions, but
found no hint.
For example:
v <- c(1, 2, 3, 4)
mysquare <- function (x) { return (x
Excellent.
Thank you very much David. Your help is greatly appreciated. "ave" worked
like a charm.
James
--
View this message in context:
http://r.789695.n4.nabble.com/Apply-Function-to-List-by-Group-Returning-Result-with-Dim-of-List-tp4311880p4312262.html
Sent from the R help mailing list arc
On Jan 19, 2012, at 6:42 PM, jamesrobinsonjnr wrote:
I have a panel data set defined as a simple data.frame with a factor
age and
income. I would like to generate the results of a set function such
as (sum,
mean, or even diff) separate for each factor (category or age group).
However I want
I have a panel data set defined as a simple data.frame with a factor age and
income. I would like to generate the results of a set function such as (sum,
mean, or even diff) separate for each factor (category or age group).
However I want the result to have the same dimension as the overal
data.fra
On 08/25/2011 10:54 AM, Tom Vanwalleghem wrote:
> Dear R helpers,
> I'm new to R and struggling with applying functions to a spatial grid data
> frame, called data for example.data has a variable named "slope" and "uparea"
> Basically, I need to calculate the tan(data$slope)Next, I need to divide
It's not clear to me what problem you're having.
tan(data$slope)
should work. As should
log(data$uparea/data$slope)
I suggest that you provide a small subset of example data along with an
example of any code you've tried, and the output that you'd like.
Jean
Tom Vanwalleghem wrote on
Dear R helpers,
I'm new to R and struggling with applying functions to a spatial grid data
frame, called data for example.data has a variable named "slope" and "uparea"
Basically, I need to calculate the tan(data$slope)Next, I need to divide
data$uparea by data$slope and take the log() of that a
For some reason when I apply a function to a single row in R it works, but
when that same row is in a data.frame it does not, see below:
apply(dx[954,], 1, query.db)
2571
1092 0.06044147
3890 0.05948577
3273 0.05911261
794 0.05855583
4241 0.05854064
3560 0.05602690
apply(dx[954
Hi,
I have a matrix with about 3000 rows, and 1 column. The contents of the matrix
are stock symbols (IBM, AAPL, etc) for instance. I also have a function that
takes a single stock symbol as an argument, parses the text of Google Finance
and returns the related stock symbols that the page has l
On 02.10.2010 18:00, PQuery wrote:
Hello,
I have a list "ll - see below" on which I would like to apply a function
accessing every pair of elements in the list. For instance, I want to apply
the "sum" function on "6635 + 6636" and return the sum, the on "6635 +
6637", ...
Any hint to do that
Hello,
I have a list "ll - see below" on which I would like to apply a function
accessing every pair of elements in the list. For instance, I want to apply
the "sum" function on "6635 + 6636" and return the sum, the on "6635 +
6637", ...
Any hint to do that using apply / mapply / rapply ?
Than
I would like to apply a function to two vectors
For example,
A<-c(NA,1,2,3,NA)
B<-6:10
I would like C to be equal to A but if any A element is NA that
corresponding c element is equal to B, i.e.
C = c(6,1,2,3,10)
#untested...
C <- ifelse(is.na(A), B, A)
__
Dear all,
I would like to apply a function to two vectors
For example,
A<-c(NA,1,2,3,NA)
B<-6:10
I would like C to be equal to A but if any A element is NA that
corresponding c element is equal to B, i.e.
C = c(6,1,2,3,10)
Please note that this is a simplified example and the real vectors ar
Try this:
y <- c(v1, v2, v3, v4)
rowf <- gl(2, 1, 16)
colf <- gl(2, 8, 16, labels=1:0)
dat <- data.frame(y)
aggregate(dat[1], list(Row=rowf, Col=colf), mean)
-Peter Ehlers
Jack Siegrist wrote:
I have a data set of many rows and many columns in which both the rows and
the columns have associat
I have a data set of many rows and many columns in which both the rows and
the columns have associated grouping factors.
Is there a way to do what 'aggregate' does but in the other dimension?
The way I have been doing this is to use 'aggregate' on the data in the
usual way and then rotate the res
Try this:
transform(testDF, value = as.numeric(paste(round(abs(x)),
round(abs(y)), sep = ".")))
On Wed, Sep 16, 2009 at 3:22 PM, Jon Loehrke wrote:
> Greetings,
>
> I am attempting to run a function, which produces a vector and
> requires two input variables, across two nested factor levels. I
Hi Jon,
Here is a suggestion:
foo <- function(x) as.numeric( paste( abs( round( x ) ), collapse = "." ) )
testDF$value <- apply( testDF[,1:2], 1, foo )
testDF
HTH,
Jorge
On Wed, Sep 16, 2009 at 3:22 PM, Jon Loehrke wrote:
> Greetings,
>
> I am attempting to run a function, which produces a ve
One correction below,
---snip---
> >
> > # example data frame
> > testDF<-data.frame(
> > x=rnorm(12),
> > y=rnorm(12),
> > f1=gl(3,4),
> > f2=gl(2,2,12))
> >
>
> Try this using lapply, split, mapply? Maybe it is in a nicer output
> object for you?
>
> testFun2 <- function(x,
Hello,
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Jon Loehrke
> Sent: Wednesday, September 16, 2009 2:23 PM
> To: r-help@r-project.org
> Subject: [R] apply function across two variables by mult fact
Greetings,
I am attempting to run a function, which produces a vector and
requires two input variables, across two nested factor levels. I can
do this using by(X, list(factor1, factor2), function), however I
haven't found a simple way to extract the list output into an
organized vector fo
ukey
>
> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> Namens Paulo Eduardo Cardoso
> Verzonden: maandag 3 augustus 2009 16:19
> Aan: David Winsemius
> CC: [R]
> Onderwerp: Re: [R] apply function to named numeric
ius
CC: [R]
Onderwerp: Re: [R] apply function to named numeric object
Both objects are numeric, but they differ in structure and I don't know
how to handle both with a single function to get means.
When I try to apply colMeans to a named numeric object like this:
Named num [1:2] 670 314
- att
The objects are
> centroid
x y
669.5 313.5
> str(centroid)
Named num [1:2] 670 314
- attr(*, "names")= chr [1:2] "x" "y"
or
> centroid
x y
[1,] 659.5 472.5
[2,] 659.5 473.5
> str(centroid)
num [1:2, 1:2] 660 660 472 474
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ :
That may just be a vector with two elements, so functions designed for
matrices are not going to "work". Why are you taking means of such
small data objects anyway?
> obj <- c(x=640, y=410)
> obj
x y
640 410
> str(obj)
Named num [1:2] 640 410
- attr(*, "names")= chr [1:2] "x" "y"
So you need to show us how you made the second object. (The Posting
Guide's phrase "reproducible code" is hereby invoked.)
On Aug 3, 2009, at 10:18 AM, Paulo Eduardo Cardoso wrote:
> Both objects are numeric, but they differ in structure and I don't
> know how to handle both with a single fu
Both objects are numeric, but they differ in structure and I don't know how
to handle both with a single function to get means.
When I try to apply colMeans to a named numeric object like this:
Named num [1:2] 670 314
- attr(*, "names")= chr [1:2] "x" "y"
I get the error messages:
Error in colM
On Aug 3, 2009, at 9:52 AM, Paulo Eduardo Cardoso wrote:
> Thanks. Works
>
> A doubt.
>
> I asked that because I have a loop that can generate objects like
> that or this one
>
>
> str(object)
> Named num [1:2] 670 314
> - attr(*, "names")= chr [1:2] "x" "y"
>
> To avoid using a ifelse() to ca
Thanks. Works
A doubt.
I asked that because I have a loop that can generate objects like that or
this one
str(object)
Named num [1:2] 670 314
- attr(*, "names")= chr [1:2] "x" "y"
To avoid using a ifelse() to calculate means of x and y, I'd like a function
that handle with this named numeric o
On Aug 3, 2009, at 9:07 AM, Paulo Eduardo Cardoso wrote:
Maybe a very basic question.
How can I get mean of a object like this
str(object)
num [1:53, 1:2] 734 734 736 734 736 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "x" "y"
I want the mean of both x and y
apply(obj
Maybe a very basic question.
How can I get mean of a object like this
> str(object)
num [1:53, 1:2] 734 734 736 734 736 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "x" "y"
I want the mean of both x and y
___
Paulo E. Cardoso
[[alternative HTML version
Hi all
I am manipulating a datafram which has 3 variables.Such as:
1 2 3
4 5 6
.
.
.
200 210 300
I also has a row index: index=c(100,200,250..300)
I want to find the sums of first 100 rows, then the sum from row 101 to row
200, then row 201 to row 250... the each end row is indicated by
Hesen Peng wrote:
Hi,
Thank you so much for the help. apply does work for the first situation.
For the second situation, I'm currently using:
temp.a<-function(i,j){
return(G(M[i,],N[j,]))
}
temp.v<-Vectorize(temp.a)
result<-outer(1:nrow(M),1:nrow(N),FUN=temp.v)
Looks pretty good!
Uwe
Hi,
Thank you so much for the help. apply does work for the first situation.
For the second situation, I'm currently using:
temp.a<-function(i,j){
return(G(M[i,],N[j,]))
}
temp.v<-Vectorize(temp.a)
result<-outer(1:nrow(M),1:nrow(N),FUN=temp.v)
And I wonder whether there are some other ways to
Hesen Peng wrote:
Hi all,
I've recently been writing functions which may deal with very large
arrays. And I hope to use *apply functions in the program so that the
code may look nicer and the performance may be better in the following
two situations.
The first situation is:
I'm having an arr
Hi all,
I've recently been writing functions which may deal with very large
arrays. And I hope to use *apply functions in the program so that the
code may look nicer and the performance may be better in the following
two situations.
The first situation is:
I'm having an array A with dim(A)==c(m,
G'day Shuba,
On Thu, 15 May 2008 12:18:58 +0530
"Shubha Vishwanath Karanth" <[EMAIL PROTECTED]> wrote:
> Getting a strange result using ?apply. Please look into the below
> codes:
>
> d=data.frame(a=c(1,2,3),b=c("A","B","C"),c=c(TRUE,FALSE,FALSE),d=c(T,F,F))
>
> > class(d[,1])
>
> [1] "numeric"
Hi R,
Getting a strange result using ?apply. Please look into the below codes:
>
d=data.frame(a=c(1,2,3),b=c("A","B","C"),c=c(TRUE,FALSE,FALSE),d=c(T,F,F
))
> class(d[,1])
[1] "numeric"
> class(d[,2])
[1] "factor"
> class(d[,3])
[1] "logical"
> class(d[,4])
[1] "logical"
> ap
90 matches
Mail list logo