Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1 city_name2 New York City Buffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ................... ................... ................... ................... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ....... If I try rep((city1,city2), 5) Error: unexpected ',' in "rep((city1," Please guide Regards MAdhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[alternative HTML version deleted]]
Hi, Take a look at rep(), specifically the each = parameter. cheers, Paul Madhavi Bhave wrote:> Dear R helpers > > I have a city.csv file as given below. > > 'city.csv' > city_name1 city_name2 > New York City Buffallo > > So I define > > city_name = read.csv('city.csv') > city1 = city_name$city_name1 > city2 = city_name$city_name2 > > My problem is how do I repeat the names one after other say 10 times i.e. my output should be like > > New York > City Buffallo > New York > City Buffallo > New York > City Buffallo > New York City > ................... > ................... > ................... > ................... > > I have tried the following commands > > rep(c(city1,city2), 5) > > and I got the output something like this > > [1] 1 1 1 1 1 1 ....... > > If I try > > rep((city1,city2), 5) > > Error: unexpected ',' in "rep((city1," > > Please guide > > Regards > > MAdhavi > > > Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > 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. >-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
Hi! I'm kind of a newboe here, but I think it is because read.csv transforms the character variables to factors. Maybe try setting the argument "as.is" in read.csv(). Or try: rep(as.character(c(city1, city2)),5) That should work. HTH Ivan Le 2/10/2010 10:44, Madhavi Bhave a écrit :> Dear R helpers > > I have a city.csv file as given below. > > 'city.csv' > city_name1 city_name2 > New York City Buffallo > > So I define > > city_name = read.csv('city.csv') > city1 = city_name$city_name1 > city2 = city_name$city_name2 > > My problem is how do I repeat the names one after other say 10 times i.e. my output should be like > > New York > City Buffallo > New York > City Buffallo > New York > City Buffallo > New York City > ................... > ................... > ................... > ................... > > I have tried the following commands > > rep(c(city1,city2), 5) > > and I got the output something like this > > [1] 1 1 1 1 1 1 ....... > > If I try > > rep((city1,city2), 5) > > Error: unexpected ',' in "rep((city1," > > Please guide > > Regards > > MAdhavi > > > Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ > [[alternative HTML version deleted]] > > > > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Dear Sirs, Thanks a lot for your guidance. It worked wonderfully. Regards Madhavi --- On Wed, 10/2/10, Ivan Calandra <ivan.calandra@uni-hamburg.de> wrote: From: Ivan Calandra <ivan.calandra@uni-hamburg.de> Subject: Re: [R] How to repeat the names? To: r-help@r-project.org Date: Wednesday, 10 February, 2010, 1:54 AM Hi! I'm kind of a newboe here, but I think it is because read.csv transforms the character variables to factors. Maybe try setting the argument "as.is" in read.csv(). Or try: rep(as.character(c(city1, city2)),5) That should work. HTH Ivan Le 2/10/2010 10:44, Madhavi Bhave a écrit :> Dear R helpers > > I have a city.csv file as given below. > > 'city.csv' > city_name1 city_name2 > New York City Buffallo > > So I define > > city_name = read.csv('city.csv') > city1 = city_name$city_name1 > city2 = city_name$city_name2 > > My problem is how do I repeat the names one after other say 10 times i.e. my output should be like > > New York > City Buffallo > New York > City Buffallo > New York > City Buffallo > New York City > ................... > ................... > ................... > ................... > > I have tried the following commands > > rep(c(city1,city2), 5) > > and I got the output something like this > > [1] 1 1 1 1 1 1 ....... > > If I try > > rep((city1,city2), 5) > > Error: unexpected ',' in "rep((city1," > > Please guide > > Regards > > MAdhavi > > > Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ > [[alternative HTML version deleted]] > > > > > ______________________________________________ > 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. >[[alternative HTML version deleted]] -----Inline Attachment Follows----- ______________________________________________ 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. [[elided Yahoo spam]] [[alternative HTML version deleted]]