[R] Counting defined character within String
Charles C. Berry
cberry at tajo.ucsd.edu
Mon Jul 5 19:59:13 CEST 2010
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 one object. In this case 3 (1|22|45)
>
>
> Does anybody know a better way?
See
?max
?count.fields
and, if you are noit using this on a text file,
?textConnection
> count.fields(textConnection("
+ Var
+ NA
+ NA
+ NA
+ NA
+ NA
+ 1
+ 1|2
+ 1|22|45
+ 3
+ 4b|24789
+ "),sep="|")
[1] 1 1 1 1 1 1 1 2 3 1 2
HTH,
Chuck
>
> Thanks
>
> Mit freundlichen Grüßen
>
> Andreas Kunzler
> ____________________________
> Bundeszahnärztekammer (BZÄK)
> Chausseestraße 13
> 10115 Berlin
>
> Tel.: 030 40005-113
> Fax: 030 40005-119
>
> E-Mail: a.kunzler at bzaek.de
>
> ______________________________________________
> R-help at r-project.org 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.
>
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the R-help
mailing list