重塑包装掩膜的形状,以防止熔化物命名色谱柱

编程入门 行业动态 更新时间:2024-10-27 06:23:22
本文介绍了重塑包装掩膜的形状,以防止熔化物命名色谱柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个同时需要reshape和reshape2库的脚本.我知道这是很差的做法,但是我认为 plyr(或我正在使用的另一个库) Vennerable正在加载reshape,我个人在很多地方都使用过reshape2.

I have a script which requires both reshape and reshape2 libraries. I know this is poor practise, but I think plyr (or another library I am using) Vennerable is loading reshape and I have personally used reshape2 in a lot of places.

问题是reshape对reshape2的屏蔽导致melt函数出现问题

The problem is that the masking of reshape2 by reshape is causing problems for the melt function

# Example data frame df <- data.frame(id=c(1:5), a=c(rnorm(5)), b=c(rnorm(5))) # With just reshape2, variable and value columns are labelled correctly library(reshape2) melt(df, measure.vars=c("a", "b"), variable.name="type", value.name="distance") id type distance 1 1 a -2.0233666 2 2 a 0.4625188 3 3 a -2.8688127 4 4 a 0.8151644 5 5 a -0.4574464 6 1 b 1.3197784 7 2 b 1.6213146 8 3 b 1.3508913 9 4 b -1.6483839 10 5 b -1.1342157 # But my script also has reshape loaded library(reshape) Loading required package: plyr Attaching package: ‘reshape’ The following object(s) are masked from ‘package:plyr’: rename, round_any The following object(s) are masked from ‘package:reshape2’: colsplit, melt, recast # When calling melt in this environment, variable and value columns stick to # their default names melt(df, measure.vars=c("a", "b"), variable.name="type", value.name="distance") id variable value 1 1 a -2.0233666 2 2 a 0.4625188 3 3 a -2.8688127 4 4 a 0.8151644 5 5 a -0.4574464 6 1 b 1.3197784 7 2 b 1.6213146 8 3 b 1.3508913 9 4 b -1.6483839 10 5 b -1.1342157

我以为我可以使用reshape2::melt从reshape2专门调用melt,但是我仍然遇到同样的问题.

I thought I could specifically call melt from reshape2 using reshape2::melt but I still get the same problem.

有没有解决这个问题的简单方法?如果没有,我将不得不在每次融化调用之后直接手动重新标记列名称.

Is there an easy way around this? If not I will have to manually relabel the column names straight after each melt call.

推荐答案

使用reshape2:::melt.data.frame(...).

melt实际上是一种方法:

> reshape2::melt function (data, ..., na.rm = FALSE, value.name = "value") { UseMethod("melt", data) } <environment: namespace:reshape2>

因此,对于数据帧,R将搜索melt.data.frame,它位于reshape中:

So, in the case of a data frame, R will search for melt.data.frame, which is in reshape:

> melt.data.frame function (data, id.vars, measure.vars, variable_name = "variable", na.rm = !preserve.na, preserve.na = TRUE, ...) { ... } <environment: namespace:reshape>

正如我所指出的,最好的解决方案可能只是升级所有内容. 确实,plyr曾经用于加载reshape,但现在不再加载.(我当时在考虑ggplot2.)

As I indicated though, the best solution might just be to upgrade everything. It is true that plyr used to load reshape, but it doesn't anymore. ( I was thinking ggplot2.)

更多推荐

重塑包装掩膜的形状,以防止熔化物命名色谱柱

本文发布于:2023-11-06 16:04:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:色谱   形状   以防止   掩膜

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!