Note that there are some explanatory texts on larger screens.

plurals
  1. POduplicate rownames error using rbind and reading the same csv file twice
    primarykey
    data
    text
    <p>I have two data frames that are identical in length and number of columns. I want to do a simple <code>rbind</code>, but get the error</p> <pre><code>&gt; outputdf&lt;-rbind(outputdf,currentcol) Error in `row.names&lt;-.data.frame`(`*tmp*`, value = value) : duplicate 'row.names' are not allowed In addition: Warning messages: 1: In `[&lt;-.factor`(`*tmp*`, iseq, value = c(2L, 2L, 2L, 2L, 2L, 2L, : invalid factor level, NA generated 2: non-unique values when setting 'row.names': </code></pre> <p>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 <code>row.names=FALSE</code> when reading the csvs and also using <code>rownames(dataframe)&lt;-NULL</code> to refresh. I even tried to redo the rownames so that</p> <pre><code>rownames(dataframe2) &lt;- c(nrow(dataframe1)+1):c(nrow(dataframe1)+nrow(dataframe2)) </code></pre> <p>which gives me a range that starts after the previous dataframe to avoid duplicate row names.</p> <p>All of this has failed. I was wondering if i was missing something.</p> <p>Here is the code, where A is a csv file that i converted from an excel sheet</p> <p>the file looks like </p> <pre><code>country USA Britain state NV product peas corn . . source cnn fox news jan-02 3 5 feb-02 3 2 . . </code></pre> <p>which i had earlier help to convert it into this format</p> <pre><code>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 </code></pre> <p>the code is</p> <pre><code> A&lt;-filenames[1] #get data as separate df datacols &lt;- read.csv(A, header = FALSE, skip = 11, strip.white = TRUE,row.names=NULL)[-c(2:4)] #get names as separate df names &lt;- read.csv(A, header = FALSE, nrows = 11, strip.white = TRUE,row.names=NULL,stringsAsFactors=FALSE)[-c(1:4)] datanames&lt;-c(1:11);datanames&lt;-cbind(datanames,names) #convertedfile dataset outputdf&lt;-data.frame() #addtime into dataframe timeframe&lt;-datacols[1];colnames(timeframe)&lt;-"time" for(colindex in 2:c(ncol(datacols))){ currentcol&lt;-timeframe #bind price col to the current dataframe price&lt;-datacols[colindex];colnames(price)&lt;-"Price" currentcol$Price&lt;-price #add the country currentcol$Country&lt;-as.character(datanames[[colindex]][1]) #add market location check&lt;-as.character(datanames[[colindex]][2]) currentcol$Market_Location&lt;-ifelse(nchar(check)&lt;1,"na",check) #add market name check&lt;-as.character(datanames[[colindex]][3]) currentcol$Market&lt;-ifelse(nchar(check)&lt;1,"na",check) #add market latitude check&lt;-as.character(datanames[[colindex]][4]) currentcol$Market_Latitude&lt;-ifelse(nchar(check)&lt;1,"na",check) #add market longitude check&lt;-as.character(datanames[[colindex]][5]) currentcol$Market_Longitude&lt;-ifelse(nchar(check)&lt;1,"na",check) #add commodity check&lt;-as.character(datanames[[colindex]][6]) currentcol$Commodity&lt;-ifelse(nchar(check)&lt;1,"na",check) #add produit agricoles check&lt;-as.character(datanames[[colindex]][7]) currentcol$produit_agricoles&lt;-ifelse(nchar(check)&lt;1,"na",check) #add price type check&lt;-as.character(datanames[[colindex]][8]) currentcol$Price.Type&lt;-ifelse(nchar(check)&lt;1,"na",check) #add unit check&lt;-as.character(datanames[[colindex]][9]) currentcol$Unit&lt;-ifelse(nchar(check)&lt;1,"na",check) #add currency check&lt;-as.character(datanames[[colindex]][10]) currentcol$Currency&lt;-ifelse(nchar(check)&lt;1,"na",check) #add source check&lt;-as.character(datanames[[colindex]][11]) currentcol$Datasource&lt;-ifelse(nchar(check)&lt;1,"na",check) #bind dataframe outputdf&lt;-rbind(outputdf,currentcol[1,]) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload