[R] sequentially process a list

Mike Lawrence Mike.Lawrence at DAL.CA
Mon May 21 17:56:17 CEST 2007


Try nested ifelse() statements to label the group

ex.
time$group=ifelse(time$time<5,NA,
	ifelse(time$time<9,1,
		ifelse(time$time<13,NA,
			ifelse(time$time<17,2,NA)
		)
	)
)

Then use aggregate to find the max value.

ex.
time.max=aggregate(time$value,list(group=time$group),max)


On 21-May-07, at 6:39 AM, Robert wrote:

> Hi dear R users,
>
> I'm a R beginner and I have a basic question about sequential  
> treatments of lists.
>
> I have a time based (i.e. events are consecutive) list of values of  
> a biological property.
>
> Like :
>
> time  value
> 1        5
> 2        10
> 3      7
> 4      10
> 5      19
> 6      21
> 7      20
> 8      18
> 9      10
> 10      7
> 11      8
> 12      12
> 13      17
> 14      19
> 15      24
> 16      18
> 17      15
> 18      10
> 19      9
> [...]
>
>
> And I have to define a threshold and to attach each event to his  
> group, i.e. values upper the threshold.
>
> Like, for a threshold value of 17
>
> time  value   group
> 1        5       NA
> 2        10      NA
> 3      7      NA
> 4      10      NA
> 5      19      1
> 6      21      1
> 7      20      1
> 8      18      1
> 9      10      NA
> 10      7      NA
> 11      8      NA
> 12      12      NA
> 13      17      2
> 14      19      2
> 15      24      2
> 16      18      2
> 17      15      NA
> 18      10      NA
> 19      9      NA
> [...]
>
>
> The only solution that I have found is to do a sequentially read  
> and write :
> for(i in 1:length(my_events_list))
> {
>     [...]
> }
>
> But I very slow. Do you have another ideas ?
>
> And after I need to extract maximum values for each group
> Like :
> group        max_value
> 1            21
> 2            24
> [...]
>
> and for each event which is part of a group to know if is't a  
> ascending phase or no.
>
>
> Yes, lot of questions !! Sorry, but I think that the solution may  
> be unique.
>
> In advance, thank you a lot
>
> regards
>
> JS
>
>
>
>
>
>
>
>        
> ______________________________________________________________________ 
> _______
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Mike Lawrence
Graduate Student, Dalhousie University Department of Psychology
http://myweb.dal.ca/mc973993

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein



More information about the R-help mailing list