With the orginal data.frame being df1 df2 <- data.frame(matrix(rep(NA, nrow(df1)*ncol(df1)), nrow = nrow(df1)))df2 <- data.frame(matrix(rep(NA, nrow(df1)*ncol(df1)), nrow = nrow(df1)))
John Kane Kingston ON Canada > -----Original Message----- > From: sahanasrinivasan...@gmail.com > Sent: Thu, 7 Mar 2013 17:23:10 +0000 > To: r-help@r-project.org > Subject: [R] Copying a dataframe > > Hi, I am trying to create a data frame using the dimensions of another > data > frame that I have input. This is the code I am using: > > tab is the data frame that is input. > c.leng<-length(tab[,1]); r.leng<-length(tab[1,]); > opdf<-data.frame(ncol=c.leng, nrow=r.leng); > a<-1; > while(a<=c.leng) > { > opdf[[1]][a]<-tab[[1]][a]; > a<-a+1; > } > > This is the error message I am getting: > Error in `[[<-.data.frame`(`*tmp*`, 1, value = c(4626L, 1L)) : > replacement has 2 rows, data has 1 > > I have tried printing out the dimensions of tab and mat separately to see > if they are the same, but tab is 4626 rows, 21 columns (which is > correct), > while mat says 1row and 2columns. > > Would be grateful if you could tell me where I am going wrong? Is there > are > better function to transfer/copy values? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.