duplicate rownames error using rbind and reading the same csv file twice

I have two data frames that are identical in length and number of columns. I want to do a simple rbind, but get the error

> outputdf<-rbind(outputdf,currentcol)
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  duplicate 'row.names' are not allowed
In addition: Warning messages:
1: In `[<-.factor`(`*tmp*`, iseq, value = c(2L, 2L, 2L, 2L, 2L, 2L,  :
  invalid factor level, NA generated
2: non-unique values when setting 'row.names':

I received help before and build two dataframes by reading the same csv twice for to get different parts of information. I am using these two data frames to build multiple data frames. However, I encounter the duplicate rownames error when using rbind. I have already tried row.names=FALSE when reading the csvs and also using rownames(dataframe)<-NULL to refresh. I even tried to redo the rownames so that

rownames(dataframe2) <- c(nrow(dataframe1)+1):c(nrow(dataframe1)+nrow(dataframe2))

which gives me a range that starts after the previous dataframe to avoid duplicate row names.

All of this has failed. I was wondering if i was missing something.

Here is the code, where A is a csv file that i converted from an excel sheet

the file looks like

country     USA      Britain
state       NV       
product     peas       corn
   .
   .
source      cnn       fox news

jan-02       3           5   
feb-02       3           2
 .
 .

which i had earlier help to convert it into this format

country state product units time    ....  source
USA      NV     peas   3     Jan-02        cnn
USA      NV     peas   3     feb-02        cnn
Britain         corn   5     jan-02       fox news
Britain         corn   2     feb-02       fox news

the code is

        A<-filenames[1]

        #get data as separate df
        datacols <- read.csv(A, header = FALSE, skip = 11, strip.white = TRUE,row.names=NULL)[-c(2:4)]

        #get names as separate df
        names <- read.csv(A, header = FALSE, nrows = 11, strip.white = TRUE,row.names=NULL,stringsAsFactors=FALSE)[-c(1:4)]
        datanames<-c(1:11);datanames<-cbind(datanames,names)


        #convertedfile dataset
        outputdf<-data.frame()

        #addtime into dataframe
        timeframe<-datacols[1];colnames(timeframe)<-"time"

        for(colindex in 2:c(ncol(datacols))){

          currentcol<-timeframe


          #bind price col to the current dataframe
          price<-datacols[colindex];colnames(price)<-"Price"
          currentcol$Price<-price

          #add the country
          currentcol$Country<-as.character(datanames[[colindex]][1])

          #add market location
          check<-as.character(datanames[[colindex]][2])
          currentcol$Market_Location<-ifelse(nchar(check)<1,"na",check)

          #add market name
          check<-as.character(datanames[[colindex]][3])
          currentcol$Market<-ifelse(nchar(check)<1,"na",check)

          #add market latitude
          check<-as.character(datanames[[colindex]][4])
          currentcol$Market_Latitude<-ifelse(nchar(check)<1,"na",check)

          #add market longitude
          check<-as.character(datanames[[colindex]][5])
          currentcol$Market_Longitude<-ifelse(nchar(check)<1,"na",check)

          #add commodity
          check<-as.character(datanames[[colindex]][6])
          currentcol$Commodity<-ifelse(nchar(check)<1,"na",check)

          #add produit agricoles
          check<-as.character(datanames[[colindex]][7])
          currentcol$produit_agricoles<-ifelse(nchar(check)<1,"na",check)

          #add price type
          check<-as.character(datanames[[colindex]][8])
          currentcol$Price.Type<-ifelse(nchar(check)<1,"na",check)

          #add unit
          check<-as.character(datanames[[colindex]][9])
          currentcol$Unit<-ifelse(nchar(check)<1,"na",check)

          #add currency
          check<-as.character(datanames[[colindex]][10])
          currentcol$Currency<-ifelse(nchar(check)<1,"na",check)

          #add source
          check<-as.character(datanames[[colindex]][11])
          currentcol$Datasource<-ifelse(nchar(check)<1,"na",check)

          #bind dataframe

          outputdf<-rbind(outputdf,currentcol[1,])

Answers


I found the problem, The dataframes i was trying to merge contained lists inside them, thats why i got the duplicate rowname error. I found this out when i wrote a test csv of a dataframe and saw how messed up it was. I used cbind of the columns instead of doing dataframe$newvariable<-data to create the dataframes


Need Your Help

My selenium browser won't close in Python

python selenium proxy

I'm trying to create a class that will have methods to test http proxies one by one until I have a working one that I can add to to a selenium webdriver instance.

jQuery blur event fired twice in Chrome

javascript jquery google-chrome

I created a simple 'infinite' form with input fields.