gpt4 book ai didi

r - 是否可以将数据帧对象转换为 tribble 构造函数?

转载 作者:行者123 更新时间:2023-12-02 03:26:26 24 4
gpt4 key购买 nike

我的数据如下所示:

library(tidyverse)
df <- tibble(
x = c(0, 179, 342, 467, 705, 878, 1080, 1209, 1458, 1639, 1805, 2000, 2121, 2339, 2462, 2676,
2857, 3049, 3227, 3403, 3583, 3651, 4009, 4034, 4151, 4194, 4512, 4523, 4679, 5789),
y = c(4.7005, 4.8598, 5.0876, 5.0938, 5.3891, 5.6095, 5.8777, 6.0064, 6.3063, 6.4723, 6.6053,
6.8145, 6.9078, 7.1701, 7.2633, 7.3865, 7.5766, 7.644, 7.8018, 7.9505, 8.0974, 8.1937,
8.2391, 8.294, 8.3143, 8.3452, 8.5092, 8.5172, 8.5993, 9.0275))

是否可以将我的 dataframe/tibble 对象转换为 tribble“构造函数”?

我正在寻找类似 dput 的东西,但更轻量级并且专门针对数据帧。

最佳答案

datapasta::dpasta() 应该合适。您的示例的输出:

dpasta(df)
tibble::tribble(
~x, ~y,
0, 4.7005,
179, 4.8598,
342, 5.0876,
467, 5.0938,
705, 5.3891,
878, 5.6095,
1080, 5.8777,
1209, 6.0064,
1458, 6.3063,
1639, 6.4723,
1805, 6.6053,
2000, 6.8145,
2121, 6.9078,
2339, 7.1701,
2462, 7.2633,
2676, 7.3865,
2857, 7.5766,
3049, 7.644,
3227, 7.8018,
3403, 7.9505,
3583, 8.0974,
3651, 8.1937,
4009, 8.2391,
4034, 8.294,
4151, 8.3143,
4194, 8.3452,
4512, 8.5092,
4523, 8.5172,
4679, 8.5993,
5789, 9.0275
)

https://cran.r-project.org/web/packages/datapasta/index.html https://github.com/MilesMcBain/datapasta

关于r - 是否可以将数据帧对象转换为 tribble 构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42839626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com