我有以下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)
我得到一个错误:
错误:行的标识符重复:...
还尝试了melt
函数的相同结果。
我已使用aws.s3::get_bucket()
函数连接到S3,并尝试将其转换为数据帧。我知道有一个aws.s3::get_bucket_df()
函数应该执行此操作,但是它不起作用(您可以查看我的relevant question。
获得存储区列表后,将其取消列出并运行enframe
命令。
请告知。
答案 0 :(得分:2)
您可以先引入一个新列(引入NA
,将不得不处理它们)。
df %>%
mutate(RN=row_number()) %>%
group_by(RN) %>%
spread(name,value)