Re: [R] sapply question

From: Afshartous, David <>
Date: Thu 29 Jun 2006 - 03:37:33 EST

My apologies for my very poor email. Below is some simplified code. I think my confusion has more to do w/ embedding the sapplpy within another function and
returning the result, thus this would apply to your "split" suggestion as well.
However, when I run this the result is still empty. thanks!
dave = function(dat) { result = sapply(levels(dat$Patient_no), function(i)

		subdat <- subset(dat, dat$Patient_no==i)
		U = subdat$UV		 
		r = numeric(6)   
		for (i in 1:6) {		
			r[i] = 2*U[i]
       r  ## results for each patient


-----Original Message-----
From: Liaw, Andy [] Sent: Wednesday, June 28, 2006 10:23 AM
To: Afshartous, David; Subject: RE: [R] sapply question

If you attached files, none made it through the mailing list.

Can't you try posting a simplified version of the problem instead? Try to make it as easy for others to help you as possible will maximize the chance you get some useful response. Asking people to read code you've attached in files isn't helping, especially if the code is long and make use of data not accessible to anyone but you.

In general, if you want something like tapply, but need several variables instead of one, you can use something like:

sapply(split(dataFrame, factor_to_split_by), function(...))


From: Afshartous, David
> sent this to the list yesterday but didn't see it listed in the daily
> summary ... apologies if you receive it twice ...
> ________________________________
> From: Afshartous, David
> Sent: Tuesday, June 27, 2006 10:02 AM
> To: ''
> Subject: sapply question
> All:
> I'm trying to use sapply to break up data within another function.
> (tapply doens't seem to work since I want to access several variables
> of a data set, not just break up a single variable according to a
> factor.) I tried the R documentation but that wasn't much help on
> this.
> The first function in the attached file works, breaking up the data
> according to patient number (6 observations per 24 patients) via a for

> loop i=1,..24.
> The second function is an attempt to use sapply instead of the first
> "for loop".
> it doesn't load properly and I seem to be absolutely blind as to why;
> my guess is that it's something "obvious". any help appreciated.
> (necessary data
> attached)
> thanks!
> dave
> ps:
> I'm on windows and,
> r.2 =100 (input to function)
> dat = comp.CAND.frm (attached file)
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

Notice: This e-mail message, together with any attachments,...{{dropped}} mailing list PLEASE do read the posting guide! Received on Thu Jun 29 03:37:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 29 Jun 2006 - 04:13:09 EST.

Mailing list information is available at Please read the posting guide before posting to the list.