传播数据框

Spread dataframe

我有以下 dataframe/tibble 示例:

structure(list(name = c("Contents.Key", "Contents.LastModified", 
"Contents.ETag", "Contents.Size", "Contents.Owner", "Contents.StorageClass", 
"Contents.Bucket", "Contents.Key", "Contents.LastModified", "Contents.ETag"
), value = c("2019/01/01/07/556662_cba3a4fc-cb8f-4150-859f-5f21a38373d0_0e94e664-4d5e-4646-b2b9-1937398cfaed_2019-01-01-07-54-46-064", 
"2019-01-01T07:54:47.000Z", "\"378d04496cb27d93e1c37e1511a79ec7\"", 
"24187", "e7c0d260939d15d18866126da3376642e2d4497f18ed762b608ed2307778bdf1", 
"STANDARD", "vfevvv-edrfvevevev-streamed-data", "2019/01/01/07/556662_cba3a4fc-cb8f-4150-859f-5f21a38373d0_33a8ba28-245c-490b-99b2-254507431d47_2019-01-01-07-54-56-755", 
"2019-01-01T07:54:57.000Z", "\"df8cc7082e0cc991aa24542e2576277b\""
)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
))

我想使用 tidyr::spread() 函数展开名称列,但我没有得到想要的结果

df %>% tidyr::spread(key = name, value = value)

我得到一个错误:

Error: Duplicate identifiers for rows:...

也尝试了 melt 函数相同的结果。

我已使用 aws.s3::get_bucket() 函数连接到 S3 并尝试将其转换为数据帧。我知道有一个 aws.s3::get_bucket_df() 函数可以做到这一点,但它不起作用(你可以看看我的 .

获得遗愿清单后,我将其取消列出并执行 运行 enframe 命令。 请指教

你可以先引入一个新的专栏(引入NAs,将不得不处理它们)。

df %>% 
mutate(RN=row_number()) %>% 
  group_by(RN) %>% 
  spread(name,value)