Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
停止dplyr在聚集(…)%中拆分名称<;%单独的(…)_R_Dplyr - Fatal编程技术网

停止dplyr在聚集(…)%中拆分名称<;%单独的(…)

停止dplyr在聚集(…)%中拆分名称<;%单独的(…),r,dplyr,R,Dplyr,在执行收集分离时,如何停止dplyr自动拆分名称 cost <- data.frame(Date = rep('1970-01-01', 3), Atr = runif(3), Atrb = runif(3), a_t = runif(3), b_t = runif(3), a_t = run

在执行
收集
分离
时,如何停止dplyr自动拆分名称

cost <- data.frame(Date = rep('1970-01-01', 3), 
                   Atr = runif(3), 
                   Atrb = runif(3), 
                   a_t = runif(3), 
                   b_t = runif(3), 
                   a_t = runif(3), 
                   b_t = runif(3), 
                   a_t = runif(3), 
                   b_t = runif(3))

names(cost) <- c('Date', 'Atr','Atrb','a_t','b_t','a_t','b_t','a_t','b_t')

# Now we reshape and see the problem
idx = 4:9 
names(cost)[idx] = paste0(names(cost)[idx], ".", c(sapply(LETTERS[1:3], rep, times = 2)) )

cost.long = cost %>%
    gather(key, value, -c(Date:Atrb)) %>%
    separate(key, into = c("Metric", "Group"))

cost.long

我们可以使用
sep
中的
sep
参数

cost.long <- cost %>%
              gather(key, value, -c(Date:Atrb)) %>%
              separate(key, into=c("Metric", "Group"), sep="_")
cost.long%
聚集(键,值,-c(日期:Atrb))%>%
分离(键,分为=c(“公制”、“组”),sep=“389;”)
cost.long <- cost %>%
              gather(key, value, -c(Date:Atrb)) %>%
              separate(key, into=c("Metric", "Group"), sep="_")