[R] How to repeat the names?

Romain Francois romain.francois at dbmail.com
Wed Feb 10 10:54:54 CET 2010


Hello,

That's not the problem here. The variables are read as factors. You can 
use the stringAsFactors argument of read.csv to turn this off:

 > read.csv( 'city.csv', stringsAsFactors = FALSE )

and then you can proceed as you did.

Romain

On 02/10/2010 10:44 AM, Paul Hiemstra wrote:
>
> 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


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/NrTG : Rcpp 0.7.5
|- http://tr.im/MPYc : RProtoBuf: protocol buffers for R
`- http://tr.im/KfKn : Rcpp 0.7.2



More information about the R-help mailing list