Forgot the second part. To replace multiple spaces with one:

gsub(" +", " ", your.data)


On 10/23/06, Nicolas Degallier <nicolas.degallier@ird.fr> wrote:
>
> Dear R'helpers,
>
> I am reading lines in a .txt file
> Each line is stocked into a n elements object, as this:
>
>
>
> [958] " 422 287 339  31 203 602 547 1026 500 366 346 227"
> [959] " 410  67  11 220 110 451 562 598 732 163 163 220"
> [960] " 179 513  95 186 102 595 333 1289 804 210 294 459"
> [961] " 276 153 307 138 126 233 623 739 521 421 209  75"
> [962] "  64 392  60  45 332 371 290 887 599 106  62 184"
> [963] " 171 168 374  43  71 567 1110 799 960 189 339 279"
> [964] " 151 353 648 150  85 422 883 962 923 296 228 273"
> [965] " 213 805 403  43 271 445 463 846 1124 345 295  85"
> [966] " 574 420 200  39 243 187 249 378 714 318 286 114"
> [967] "  85  73 192  91 146 484 710 782 750 321 261  65"
> [968] "  53 487  27  76 150 345 663 848 620 192 129 187"
> [969] " 461 216  8 251 279 558 1012 838 1330 258 138 115"
> [970] "  53  83  39 298 117 488 880 815 1087 390 266 355"
> [971] " 225 184 173 121 167 416 411 667 605 172  60 157"
> [972] " 318 138 552 192 100 461 450 852 190 361  17 192"
>
>
>
> Now, I would like to determine how many " " (space) there are in each
> line ...
>
> After to have wipes out the extra spaces (double spaces) with
>
> data1[i]<-gsub(x=data1[i],pattern="  ",replacement="
> ",fixed=FALSE,extended=FALSE)
>
> I have attempted with regrexpr, sub, strsplit and many other
> character fonctions but I could not obtain the number of " " in each
> line, in order to further do a test on it.
>
> The answer may be trivial but at this time I gave up!!
>
> Cheers
>
> Nicolas Degallier
>
> UMR 7159 / IRD UR182
> Laboratoire d'Océanographie et du Climat, Expérimentation et
> Approches Numériques (LOCEAN)
> Tour 45-55, 4e ét., case 100, 4 place Jussieu
> 75252  Paris Cedex 5  France
> tél: (33) 01 44 27 51 57
> fax: (33) 01 44 27 38 05
>
> E-mail: <Nicolas.Degallier@ird.fr>
> pdf reprints (login="anonymous"; password="your@email.address"):
> ftp://ftp.lodyc.jussieu.fr/LOCEAN/ndelod
>
> ______________________________________________
> R-help@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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

