簡體   English   中英

R _ 組合不同大小的多個數據框和列

[英]R _ Make combinations of multiple dataframes & columns of different size

我在這里的第一個問題...

我有 2 個數據框,它們的行數都不同。 第一個有 3 列,第二個有 1 列。

I want to make all combinations of values from the 1st column of the 1st dataframe with values in the 1st (and only) column of the second dataframe, and values of 2nd column of 1st dataframe with values in 1st (and only) column of second dataframe,等等......我假設結果將是一列 dataframe(?)。

像這樣的東西:

在此處輸入圖像描述

嘗試使用 combn 並沒有幫助我......

謝謝!

可能不完全是您想要的,但提供了一個起點。 提供您的第一個 dataframe 稱為df另一個(帶有一列) df2

#make data long using tidyr
df_long <- tidyr::pivot_longer(df, cols = c("loc1", "loc2", "loc3"))

#cartesian join with codes column
CJ(df_long$value, df2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM