[R] Possible loop/ if statement query

Benjamin Gillespie gybrg at leeds.ac.uk
Thu Oct 10 00:39:14 CEST 2013

Dear r genii,

I hope you can help.

I have vector 'b':


and, from 'b' I wish to create vector 'c':

c=c(	NA,NA,NA,NA,NA,NA,1,1,1,1,1,1,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,2,2,2,2,2,2,2,2,2,2,2,NA,3,3,3,3,3,3,3)

The rules I want to use to create 'c' are:

A numeric of equal to, or over 7 in 'b' needs to result in a numeric (i.e. not NA) in 'c';
A numeric of less than 7 in 'b' needs to result in "NA" in 'c';
Where 'groups' of numerics equal to, or over 7 in 'b' are present (i.e. next to each other in the list), the numerics produced in 'c' all need to be the same;
Each 'group' of numerics in 'b' must result in a unique numeric  in 'c' (and, ideally, they should run in sequence as in 'c' above (1,2,3...).

If anyone has any idea where to start on this or can crack it I'll be most grateful!!

Many thanks in advance, 

Ben Gillespie, Research Postgraduate
School of Geography, University of Leeds, Leeds, LS2 9JT
Tel: +44(0)113 34 33345
Mob: +44(0)770 868 7641

More information about the R-help mailing list