Hi all I'm have a character vector and would like to suppress the blanks if there are more than one after the other. Example: Character value is: "abc def ghi" The result should be: "abc def ghi" I know that it's possible to delete the leading blanks with the command "trim". But how can I delete blanks within a character? Thank you very much in advance for an answer Thomas
> x <- "abc def ghi" > gsub(" +", " ", x)[1] "abc def ghi">On 10/27/06, thsudler@swissonline.ch <thsudler@swissonline.ch> wrote:> > Hi all > > I'm have a character vector and would like to suppress the blanks if there > are more than one after the other. > > Example: > > Character value is: "abc def ghi" > The result should be: "abc def ghi" > > I know that it's possible to delete the leading blanks with the command > "trim". But how can I delete blanks within a character? > > Thank you very much in advance for an answer > Thomas > > ______________________________________________ > 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]]
> c <- "abc def ghi" > gsub(" +"," ", c)[1] "abc def ghi">On Fri, 27 Oct 2006 thsudler at swissonline.ch wrote:> Hi all > > I'm have a character vector and would like to suppress the blanks if there are more than one after the other. > > Example: > > Character value is: "abc def ghi" > The result should be: "abc def ghi" > > I know that it's possible to delete the leading blanks with the command "trim". But how can I delete blanks within a character? > > Thank you very much in advance for an answer > Thomas > > ______________________________________________ > 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. >
Thank you very much... this command is exactly what I need. I only had something in the back of my mind that there is another command similar to trim to suppress blanks/spaces. But however, the gsub command works great...> c <- "abc def ghi" > gsub(" +"," ", c)[1] "abc def ghi">On Fri, 27 Oct 2006 thsudler at swissonline.ch wrote:> Hi all > > I'm have a character vector and would like to suppress the blanks if there are more than one after the other. > > Example: > > Character value is: "abc def ghi" > The result should be: "abc def ghi" > > I know that it's possible to delete the leading blanks with the command "trim". But how can I delete blanks within a character? > > Thank you very much in advance for an answer > Thomas > > ______________________________________________ > 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. >______________________________________________ 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.