Re: [R] Counting defined character within String

2010-07-05 Thread Charles C. Berry
On Mon, 5 Jul 2010, Kunzler, Andreas wrote: Dear list, I'm looking for a way to count the number of "|" within an object. The character "|" is used to separated ids. Assume a data (d) structure like Var NA NA NA NA NA 1 1|2 1|22|45 3 4b|24789 I need to know the maximum number of ids within o

Re: [R] Counting defined character within String

2010-07-05 Thread Marc Schwartz
On Jul 5, 2010, at 9:04 AM, Kunzler, Andreas wrote: > Dear list, > > I'm looking for a way to count the number of "|" within an object. > The character "|" is used to separated ids. > > Assume a data (d) structure like > > Var > NA > NA > NA > NA > NA > 1 > 1|2 > 1|22|45 > 3 > 4b|24789 > > I n

Re: [R] Counting defined character within String

2010-07-05 Thread Henrique Dallazuanna
Try this: sapply(strsplit(as.character(Var$Var), "\\|"), length) On Mon, Jul 5, 2010 at 11:04 AM, Kunzler, Andreas wrote: > Dear list, > > I'm looking for a way to count the number of "|" within an object. > The character "|" is used to separated ids. > > Assume a data (d) structure like > > Var

[R] Counting defined character within String

2010-07-05 Thread Kunzler, Andreas
Dear list, I'm looking for a way to count the number of "|" within an object. The character "|" is used to separated ids. Assume a data (d) structure like Var NA NA NA NA NA 1 1|2 1|22|45 3 4b|24789 I need to know the maximum number of ids within one object. In this case 3 (1|22|45) Does any