#organise dataframe from depmap colnames(HumagneCDLogfoldChangeguidedataintermediate) <-…
- User
#organise dataframe from depmap colnames(HumagneCDLogfoldChange_guide_data_intermediate) <- HumagneCDLogfoldChange_guide_data_intermediate[1,] HumagneCDLogfoldChange_guide_data_intermediate <- HumagneCDLogfoldChange_guide_data_intermediate[-1,] colnames(HumagneCDLogfoldChange_guide_data_intermediate)[1] <- "Gene" HumagneCDLogfoldChange_guide_data_intermediate$source <- "DepMap"
#change first colname colnames(result_df)[1] <- "Gene" result_df$source <- "Metz"
DepMap_and_Metz_Humagne_combined <- inner_join(HumagneCDLogfoldChange_guide_data_intermediate, result_df, by = "Gene")
DepMap_and_Metz_Humagne_combined <- inner_join(HumagneCDLogfoldChange_guide_data_intermediate, result_df, by = "Gene") Error in
inner_join(): ! Input columns inxmust be unique. ✖ Problem withSC.000067.CD02_CD.1_14_A,SC.000097.CD01_CD.1_14_A,SC.000147.CD01_CD.1_14_A,SC.000183.CD01_CD.1_14_A,SC.000292.CD02_CD.1_14_A,SC.000404.CD01_CD.1_14_A,SC.000502.CD01_CD.1_14_A,SC.000527.CD01_CD.1_14_A,SC.000583.CD01_CD.1_14_A,SC.000696.CD01_CD.1_14_A,SC.000774.CD01_CD.1_14_A,SC.000900.CD01_CD.1_14_A,SC.001509.CD01_CD.1_14_A,SC.001619.CD01_CD.1_14_A,SC.001975.CD01_CD.1_14_A,SC.001975.CD01_CD.1_21_A,SC.001975.CD01_CD.1_14_B,SC.001975.CD01_CD.1_21_B,SC.001975.CD01_CD.1_14_C, andSC.001975.CD01_CD.1_14_D. Runrlang::last_trace()to see where the error occurred.I am sure the dataframes i want to combine contain the same stuff
- Assistant
The error message you're getting indicates that there are duplicated column names in the
HumagneCDLogfoldChange_guide_data_intermediatedata frame. When trying to perform aninner_join, column names in both data frames need to be unique for the join to properly associate matching rows based on designated columns.The problem you face is not with the
Genecolumn but is related to other columns that have duplicative names within theHumagneCDLogfoldChange_guide_data_intermediatedataframe. This often occurs when your data may have multiple measurements or entries for the same feature but haven't been distinctly labeled.Here's how you can troubleshoot and fix the issue:
Step 1: Ensure there are no duplicate column names in
HumagneCDLogfoldChange_guide_data_intermediate.# Check for any duplicate column names any(duplicated(colnames(HumagneCDLogfoldChange_guide_data_intermediate)))If this returns
TRUE, you need to address the duplicated column names. Here's one way to make column names unique usingmake.unique:# Make column names unique colnames(HumagneCDLogfoldChange_guide_data_intermediate) <- make.unique(colnames(HumagneCDLogfoldChange_guide_data_intermediate))Step 2: Now retry your
inner_join:DepMap_and_Metz_Humagne_combined <- inner_join(HumagneCDLogfoldChange_guide_data_intermediate, result_df, by = "Gene")If the error persists, you might also want to check that no columns in
result_dfalso have that same issue.In terms of organization, your first few steps looked fine:
- You're setting the column names from the first row of one of your data frames,
- Removing that first row so it doesn't interfere with the actual data,
- And, you're amending the first column name and adding a
sourcecolumn.
Once you've resolved any potential issues with duplicate column names, your merging operation should work.
Make sure that the
inner_joinis what you intended to use, which merges data frames by keeping rows that have matching values in both data frames. If you want to combine all rows from both data frames, regardless of whether there are matches or not, you might consider usingfull_joininstead. If you specifically want to keep all rows from one and bring in matching rows from the other, considerleft_joinorright_join.