saving . . . saved Adding Multiple Data Frame has been deleted. Adding Multiple Data Frame has been hidden .
Adding Multiple Data Frame
Title
Question
Firstly, I performed rbind to add new data row.
Then, the csv file is updated by doing write.csv operation.
By running the R script file again, new column (X) exists in the dataframe and that makes number of columns of arguments do not match problem for further data frame addition.
How to solve it?

I also attached my code.
captaincy=read.csv("CaptaincyData.csv")
captaincy <- rbind(captaincy,data.frame(names="Dravid",Y=2008,played=25,won=8,lost=6,victory=0.32))
write.csv(captaincy,"CaptaincyData.csv")



In adding new column using cbind by running R script file repeatedly, new column exists. (in this case: just only new column exists)

R Operations-on-Matrices-and-Data-Frames 08-09 min 40-50 sec 09-11-19, 3:39 p.m. EKW

Answers:

Please send us the exact error which you are encountering.
09-11-19, 4:04 p.m. wangikarsmita2019@gmail.com


Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match
09-11-19, 4:11 p.m. EKW


Please view the captaincy data set by using the "View(captaincy)" command and check whether there are any other columns except names, Y, played, won, lost and victory. If there are, then that is creating the problem of mismatch.
09-11-19, 4:23 p.m. wangikarsmita2019@gmail.com
I encounters the error ( rbind error) after running the following R file repeatedly.

"matrix.R" file
captaincy=read.csv("CaptaincyData.csv")
captaincy <- rbind(captaincy,data.frame(names="Dravid",Y=2008,played=25,won=8,lost=6,victory=0.32))
write.csv(captaincy,"CaptaincyData.csv")

And new column exists automatically by running the above-mentioned code repeatedly.

So, the question is why that column exists automatically by running the same code repeatedly
09-11-19, 4:26 p.m. EKW

Login to add comment


I encounters the error ( rbind error) after running the following R file repeatedly.

"matrix.R" file
captaincy=read.csv("CaptaincyData.csv")
captaincy <- rbind(captaincy,data.frame(names="Dravid",Y=2008,played=25,won=8,lost=6,victory=0.32))
write.csv(captaincy,"CaptaincyData.csv")

And new column exists automatically by running the above-mentioned code repeatedly.

So, the question is why that column exists automatically by running the same code repeatedly
09-11-19, 4:30 p.m. EKW


When you are creating a CSV file then it is automatically assuming the index column of the data frame as a separate data column and hence adding it separately in the CSV file which explains why you are getting more columns every time you run the command. This is because you are accessing the newly created "CaptaincyData.csv" file which has one more column than the original one.
09-11-19, 4:31 p.m. wangikarsmita2019@gmail.com


There may be cases where the existing csv file needs to be modified by adding new data frames frequently.
In that case, how to handle?
09-11-19, 4:35 p.m. EKW


The <a href="https://r-lang.com/cbind-in-r/">cbind()</a> and <a href="https://r-lang.com/rbind-in-r/" target="" title="">rbind()</a> functions are generic methods for data frames. These data frame functions will be used if at least one argument is a data frame and the other arguments are vectors or matrices. To merge two data frames (datasets) horizontally, use the merge() function in the R language.


06-02-21, 2 p.m. rsa92


Log-in to answer to this question.