Rstudio need to copy multiple columns from one data frame into certain corresponding columns in a different data frame

Hello!

I am trying to automate a process in Rstudio that I have to manually complete in excel. Currently, I have two excels docs loaded into Rstudio as two different data frames DF1 and DF2. I need to copy information from these excel docs/data frames into specific columns in the new data frame DF3.
Ex: df1$'group ID' is equal to the df3$'ID' column and df2$'Item ID' is also equal to the df3$'ID' column. Furthermore, I need to copy the information across multiple columns into specific columns in DF3. So DF1 has multiple columns, but I need the corresponding information from DF1$'group ID', DF1$'date', DF1$'item number' .. copied into the DF3$ID, DF3$'date', and DF3$'item' columns.

I think you are describing join operations, you can perform joins between dataframes easily with the dplyr packages, take a look at the documentation

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Hi! so I have three excel doc loaded into R studio as data frames. The first df doc has 8932 obs. with 14 variables. The second has 1142 obs with 16 variables. The third df has 0 obs. and 19 variables. I need to copy and paste information from the first and second df's to populate certain columns in the third df. I am running into issues trying to use join and even paste because the third excel doc is empty. To summarize, I need to copy specific columns from df1 and df2 into df3 to populate it. I know the columns I need to copy from each doc and where they need to be pasted into the third df, but I am unable to get the copy and paste to be successful.

Ex: df3$id <- paste(df2$"Item_ID")

output: Error: Assigned data paste(df2$\"Item_ID"`)` must be compatible with existing data.
x Existing data has 0 rows.
x Assigned data has 8932 rows.
i Only vectors of size 1 are recycled.

You can't arbitrarily put together vectors from different lengths as columns in a dataframe, if they are of differnt length, you need to define the logic to match the rows from one dataframe to the other.

As I said before, if you need specific advice, we are going to need a proper reproducible example to help you, please read the guide on the link I gave you before and try to make one.

We really should have a description in substantive terms telling us what you are doing. See The XY Problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.