0

I’m using RODBC for a database migration. I got a table in the origin, create a data frame and insert in the destination. This is working properly BUT in some cases the columns in the dest are in a different order (i dont know the order) and got an error for the data types. For example:

Col1 Col2 col3
 A1.   B1.  C1
 A2.   B2.  C2

In the destination I have:

Col3 Col1 Col2

I am doing a loop in dest for the colnames (because is the correct order ) and assign the content from orig;

Dest[,Col3] <- orig[,Col3]

And giving an error because dest has 0 rows. Do you have any idea how to solve it?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Hi Franchi MuncharaZ. It's almost impossible to guess what the problem is without additional information. [Here you can find important information on how to provide the necessary information](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) that helps others to help you. – dario Feb 08 '20 at 01:12
  • But for starters: The error message tells you that `Dest` is an empty data.frame and you are trying to assign a column with at least one row to it. – dario Feb 08 '20 at 01:14
  • yes @dario ¡, it's and empty data frame and i wanted to populate with the values of other dataframes in a specific order . Thanks for edditing the post :) – FranchiBwoy Feb 10 '20 at 18:53

1 Answers1

0

Try:

dest[names(orig)] <- orig
iod
  • 7,412
  • 2
  • 17
  • 36