[R] apologes if you already saw this :efficiency question

markleeds at verizon.net markleeds at verizon.net
Wed Jul 5 23:33:24 CEST 2006


hi everyone : i'm not sure if my previous mail about
this got sent. i was typing and
erroneosuyl hit a button and lost what i was typing.

anyway, i have the code below ( it works ) in which i run through the rows of a dataframe, taking out the first two
fields which are characters strings ( with some extra spacing so
i yuse gsub) and appending these character strings to a list so that i can build one big list.

there are 17,000 rows so i was hoping there might be a ( even just slightly. it doesn't have to be incresible improvement ) more efficient way to do this. I also think that remember someone saying that using the c command to make something bigger is not a good idea.

the code is below. thanks.

              for paircounter in 1:nrow(tempdata) {

                 firsstock<-gsub(" ","",tempdata[paircounter,1]
                 secondstock<-gsub(" ","",tempdata[paircounter,2]

                  if ( paircounter == 1 ) {
                      stocklist<-c(firststock,secondstock)
                   } else {
                       stocklist<(stocklist,firststock,secondstock)
                   }
                 }



More information about the R-help mailing list