Re: [R] by function does not separate output from function with mulliple parts

2023-10-25 Thread Rui Barradas
Às 00:22 de 25/10/2023, Sorkin, John escreveu: Colleagues, I have written an R function (see fully annotated code below), with which I want to process a dataframe within levels of the variable StepType. My program works, it processes the data within levels of StepType, but the usual headers t

Re: [R] by function does not separate output from function with, mulliple parts

2023-10-25 Thread Leonard Mada via R-help
Dear John, Printing inside the function is problematic. Your function itself does NOT print the labels. Just as a clarification: F = factor(rep(1:2, 2)) by(data.frame(V = 1:4, F = F), F, function(x) { print(x); return(NULL); } ) #   V F # 1 1 1 # 3 3 1 #   V F # 2 2 2 # 4 4 2 # F: 1 <- this i

Re: [R] by function with sum does not give what is expected from by function with print

2020-07-23 Thread Rui Barradas
Hello, These two gives the same results: aggregate(values ~ sex + status, mydata, sum) #  sex status values #1   0  0    224 #2   1  0   5227 #3   0  1 11 #4   1  1    552 by(mydata$values, list(mydata$sex, mydata$status), sum) #: 0 #: 0 #[1] 224 #-

Re: [R] by function with sum does not give what is expected from by function with print

2020-07-23 Thread Rasmus Liland
On 2020-07-24 01:48 +0200, Rasmus Liland wrote: > aggregate(x=list("values"=mydata$values), > by=list("sex"=mydata$sex, > "status"=mydata$status), > FUN=sum) > > yields > > sex status values > 1 0 0224 >

Re: [R] by function with sum does not give what is expected from by function with print

2020-07-23 Thread Rasmus Liland
On 2020-07-23 18:54 -0400, Duncan Murdoch wrote: > On 23/07/2020 6:15 p.m., Sorkin, John wrote: > > Colleagues, > > The by function in the R program below is not giving me the sums > > I expect to see, viz., > > 382+170=552 > > 4730+170=4900 > > 5+6=11 > > 199+25=224 > > ###

Re: [R] by function with sum does not give what is expected from by function with print

2020-07-23 Thread Duncan Murdoch
On 23/07/2020 6:15 p.m., Sorkin, John wrote: Colleagues, The by function in the R program below is not giving me the sums I expect to see, viz., 382+170=552 4730+170=4900 5+6=11 199+25=224 ### #full R program: mydata <- data.frame(covid=c(0,0,0,

Re: [R] by function with sum does not give what is expected from by function with print

2020-07-23 Thread Bert Gunter
by() chooses **data frame** subsets -- sum() is acting on these frames, adding up everything in them. Try this instead: > by(mydata,list(mydata$sex,mydata$status),function(x)sum(x$values)) : 0 : 0 [1] 224 --- : 1 : 0 [1] 5227

Re: [R] by function error

2017-04-20 Thread PIKAL Petr
Hi The problem is in your function, not in by. > dstats(mtcars[,c('mpg', 'hp')]) Error in is.data.frame(x) : (list) object cannot be coerced to type 'double' In addition: Warning message: In mean.default(x) : argument is not numeric or logical: returning NA > Your function expects vector but y

Re: [R] by Function Result Factor Levels

2015-09-16 Thread David L Carlson
10 24 43 6B H 13 17 28 --------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf O

Re: [R] by Function Result Factor Levels

2015-09-16 Thread Dario Strbenac
Good day, Yes, exactly. I found that aggregate is another alternative which doesn't require a package dependency, although the column formatting is less suitable, always prepending x. aggregate(warpbreaks[, 1], warpbreaks[, 2:3], function(breaks) c(Min = min(breaks), Med = median(breaks), Max

Re: [R] by Function Result Factor Levels

2015-09-15 Thread William Dunlap
Do you want something like the following? > library(dplyr, quietly=TRUE, warn.conflicts=FALSE) > warpbreaks %>% group_by(wool, tension) %>% summarize(Min=min(breaks), > Median=median(breaks), Max=max(breaks)) Source: local data frame [6 x 5] Groups: wool wool tension Min Median Max 1A

Re: [R] "By" function Frame Conversion (with Multiple Indices)

2013-01-04 Thread arun
Hi, You could try this: dat1<-read.table(text=" id,age,weight,height,gender 1,22,180,72,m 2,13,100,67,f 3,5,40,40,f 4,6,42,,f 5,12,98,66, 6,50,255,60,m ",sep=",",header=TRUE,stringsAsFactors=FALSE,na.strings="") list1<-by(dat1[c("weight","height")],dat1[c("age","gender")],colMeans,na.rm=TR

Re: [R] "By" function Frame Conversion (with Multiple Indices)

2013-01-03 Thread David Winsemius
On Jan 3, 2013, at 9:00 PM, Ray DiGiacomo, Jr. wrote: Hello, I have the following dataset. Please note that there are missing values on records 4 and 5: id,age,weight,height,gender 1,22,180,72,m 2,13,100,67,f 3,5,40,40,f 4,6,42,,f 5,12,98,66, 6,50,255,60,m I'm using the "By" function lik

Re: [R] By function

2011-04-10 Thread Raoni Rodrigues
Liviu, Thanks for your attention and help! Sorry for attached csv file, I didn't read R-Help Posting guide careful. Another R-helper thaught me use de dput() function, and this output are in email's end. Your correction in my code works pretty well!! Now I can understand a little more how the R

Re: [R] By function

2011-04-09 Thread Liviu Andronic
Hello On Fri, Apr 8, 2011 at 12:38 AM, Raoni Rodrigues wrote: > Hello all! > > I have a data frame with nine variables and 293 cases. (attached goes > the csv file). > The CSV didn't get through so it's difficult to replicate your example. Please post the output of: str(cpue) > I need to calcul

Re: [R] by function ??

2010-01-05 Thread Matthew Dowle
sage > news:77eb52c6dd32ba4d87471dcd70c8d7000243c...@na-pa-vbe03.na.tibco.com... >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of L.A. >> Sent: Saturday, December 12, 2009 12:39 PM >> To: r-help@

Re: [R] by function ??

2009-12-23 Thread Matthew Dowle
You asked how to 'create confidence intervals around the median'. Since intervals was plural and you asked within the context of 'by' LEAID then that made sense and I guessed you meant 'confidence interval around the median ratio of each group'. I already assumed you had posted a small subset o

Re: [R] by function ??

2009-12-22 Thread L.A.
Thanks, but that produces what I think is an estimated interval. I really want to use the above formula. I just can't figure out how to get it to run by the LEAID. It does require 9 observations to produce an interval, but I was showing a sample. Thanks again. L.A. Matthew Dowle-3 wrote: > >

Re: [R] by function ??

2009-12-22 Thread Matthew Dowle
Maybe this (with enough data for a CI) ? : > Dataset = data.table(Dataset) > Dataset[,as.list(wilcox.test(ratio,conf.int=TRUE)$conf.int),by="LEAID"] LEAID V1 V2 [1,] 6307 0.720 0.92 [2,] 8300 0.5678462 0.83 Warning messages: 1: In switch(alternative, two.sided

Re: [R] by function ??

2009-12-21 Thread L.A.
Well, I'm back again. Thanks for all the help. Besides working, it's helping me begin to understand how these functions work. I still have trouble reading or following the process of a function, which brings my next question: Dataset: LEAID ratio 3 6307 0.720 1 6307 0.7623810

Re: [R] by function ??

2009-12-21 Thread Matthew Dowle
-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of L.A. > Sent: Saturday, December 12, 2009 12:39 PM > To: r-help@r-project.org > Subject: Re: [R] by function ?? > > > > Thanks for all the help, They all worked, But I'm stuck again. > I've

Re: [R] by function ??

2009-12-12 Thread David Winsemius
On Dec 12, 2009, at 3:38 PM, L.A. wrote: Thanks for all the help, They all worked, But I'm stuck again. I've tried searching, but I not sure how to word my search as nothing came up. Here is my new hurdle, my data has 7 abservations and my results have 2 answers: Here is my data

Re: [R] by function ??

2009-12-12 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of L.A. > Sent: Saturday, December 12, 2009 12:39 PM > To: r-help@r-project.org > Subject: Re: [R] by function ?? > > > > Thanks for all the help,

Re: [R] by function ??

2009-12-12 Thread L.A.
Thanks for all the help, They all worked, But I'm stuck again. I've tried searching, but I not sure how to word my search as nothing came up. Here is my new hurdle, my data has 7 abservations and my results have 2 answers: Here is my data LEAID ratio 3 6307 0.720 1 6307

Re: [R] by function ??

2009-12-09 Thread Meyners, Michael, LAUSANNE, AppliedMathematics
other situations. Michael > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Ista Zahn > Sent: Mittwoch, 9. Dezember 2009 02:54 > To: L.A. > Cc: r-help@r-project.org > Subject: Re: [R] by function ?? &

Re: [R] by function ??

2009-12-08 Thread Ista Zahn
Hi, I think you want by(TestData[ , "RATIO"], LEAID, median) -Ista On Tue, Dec 8, 2009 at 8:36 PM, L.A. wrote: > > I'm just learning and this is probably very simple, but I'm stuck. >   I'm trying to understand the by(). > This works. > by(TestData, LEAID, summary) > > But, This doesn't. > > by

Re: [R] "by" function "half-working" when used in a custom function

2008-02-25 Thread Gabor Grothendieck
Please give minimal reproducible examples. The data and a test driver were missing. See last line to every message to r-help. The problem is discussed here: http://tolstoy.newcastle.edu.au/R/help/06/08/32017.html On Mon, Feb 25, 2008 at 10:05 AM, vincent chouraki <[EMAIL PROTECTED]> wrote: > Dear