Hi On 29/05/2011 2:02 a.m., Dennis Murphy wrote:
Homework question?
Indeed it is.Dear 220 student. The resources at your university, including your lecturer, should be your first port of call for questions on labs and assignments. Also, if you ever post questions on a forum like this you should make it VERY clear that you are asking about assessed coursework.
Paul p.s. That's a character vector you are working with, not a data frame.
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<xiaerwh...@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@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.______________________________________________ R-help@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.
-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ ______________________________________________ R-help@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.