旋转较长的前缀更长
我必须使此DataFrame mencem_moran 更长的时间才能进行可视化。
我基本上有一个常见的列距离,然后是16个变量的MoranIndex和Zscore(社区,CSRSTRATEGY, + 14),
我试图更长的时间与下面的代码相关。问题是 我不能将支柱作为第三列(必不可少的,因为它将有助于区分观测值),而单列具有价值。
try1 <- Increm_Moran %>%
pivot_longer(
cols = -Distance,
names_to = "Pillar",
values_to = "Value")
try2 <- Increm_Moran %>%
pivot_longer(
cols = -Distance,
names_to = c(".value", "Pillar"),
names_sep = "_",
values_drop_na = TRUE)
第二次尝试似乎与我更相关。仅缺少两列:
- 另外一列值带有数值数据,
- 另一列带有支柱的名称(社区,CSRSTRATTRETATEGY等)。
价值 | 支柱 |
---|---|
12.1 | 社区 |
12.34 | 社区 |
43.43 | CSRSTRATEGY |
34.34 | CSRSTRATTRATEGY |
枢纽会使头痛非常快,如果您有任何建议,非常感谢您
I have to make this dataframe Increm_Moran longer in order to make visualisations.
I have basically a common column distance, and then MoranIndex and zscore for 16 variables (community, csrstrategy, + 14 more)
I have tried to pivot longer with code below. Problem is
I can't have Pillar as a third column (essential because it will help differentiate observations), and single column with value.
try1 <- Increm_Moran %>%
pivot_longer(
cols = -Distance,
names_to = "Pillar",
values_to = "Value")
try2 <- Increm_Moran %>%
pivot_longer(
cols = -Distance,
names_to = c(".value", "Pillar"),
names_sep = "_",
values_drop_na = TRUE)
The second attempt seems more relevant to me. Just two columns are missing :
- one more column value with numerical data,
- another with the name of pillar (community, csrstrategy, etc).
Value | Pillar |
---|---|
12.1 | community |
12.34 | community |
43.43 | csrstrategy |
34.34 | csrstrategy |
Pivoting gives headaches really fast, if you have any advice, thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在写这篇文章时找到了答案。
我给出答案
如果这可以帮助其他人和输出,
:
I found my answer while writing this post.
I give the answer if this can help other people
and the output :