【发布时间】:2019-12-20 07:08:32
【问题描述】:
这肯定是一个基本问题,但找不到解决方法。
我需要为每组 (fs) 的最小值 (dds_min) 到最大值 (dds_max) 创建一系列值。 这是我的数据:
fs <- c("early", "late")
dds_min <-as.numeric(c("47.2", "40"))
dds_max <-as.numeric(c("122", "105"))
dds_min.max <-as.data.frame(cbind(fs,dds_min, dds_max))
这就是我所做的......
dss_levels <-dds_min.max %>%
group_by(fs) %>%
mutate(dds=seq(dds_min,dds_max,length.out=100))
我打算创建一个新变量 (dds),它的长度必须为 100,并且根据“fs”以不同的值开始和结束。我的期望是以另一个数据框(dss_levels)结束,它有两列(fs 和 dds),上面有 200 个值。
但是我收到了这个错误。
Error: Column `dds` must be length 1 (the group size), not 100
In addition: Warning messages:
1: In Ops.factor(to, from) : ‘-’ not meaningful for factors
2: In Ops.factor(from, seq_len(length.out - 2L) * by) :
‘+’ not meaningful for factors
任何帮助将不胜感激。
谢谢!
【问题讨论】:
-
不要使用
as.data.frame(cbind(fs,dds_min, dds_max))。cbind()使所有内容成为矩阵,在转换为数据框之前将所有内容转换为character。如果直接使用data.frame(fs,dds_min, dds_max),没有问题。