[R] remove ", " at the end of each line for all lines except the first line in a data frame

Dennis Murphy djmuser at gmail.com
Sat May 28 16:02:56 CEST 2011


Homework question? This one's pretty easy; see

?regex
?gsub

A couple of examples on gsub()'s help page are rather close to what
you need. The basic structure is

gsub(<string to replace>, <replacement string>, name_of_string)

where the strings are enclosed in quotes. If you need to apply this
function to each row of your data frame, see ?apply and put the gsub()
code into an anonymous function.

Best of luck!
Dennis


On Sat, May 28, 2011 at 5:54 AM, xiaerwhite <xiaerwhite at hotmail.com> wrote:
> the question ask me to use gsub() and subsetting to remove the comma at the
> end of the for all but the first value in a data frame.
>
> the first few lines are like the following:
> [1] "2177663,-41,175,2678248,6021224,1840,5,25,17,,,6,,"
>  "2177691,-39.6,176.2,2784798,6173592,1843,7,8,5,30,,7.6,12,"
> [3] "2177754,-47,166,1977803,5333806,1846,7,13,6,20,,63,,"
> "2177759,-41,172,2425856,6022664,1846,11,18,19,,,65,,"
> [5] "2177762,-41,174.5,2636191,6022065,1846,12,4,5,45,,6,,"
> "2177819,-41.9,173.60001,2559794,5923028,1848,10,15,14,10,,7.4,12,"
>
> this data frame is called the originalQuakes
>
> thank you for reading this, and please help!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/remove-at-the-end-of-each-line-for-all-lines-except-the-first-line-in-a-data-frame-tp3557391p3557391.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list