Commit 463dce46 authored by Virgile Baudrot's avatar Virgile Baudrot
Browse files

improve melt by keeping factors

parent fd2b49f1
Pipeline #788 passed with stage
in 5 minutes and 31 seconds
......@@ -114,8 +114,14 @@ fd_melt <- function(x, key, id = NULL, keep = NULL){
#' @export
#'
fd_melt_STICK = function(x, key1, keep){
vec = do.call("c", lapply(1:nrow(x),
function(i){ rep(x[[keep]][i], length(x[[key1]][[i]]))}))
if(is.factor(x[[keep]])){
vec = factor(do.call("c", lapply(1:nrow(x),
function(i){ as.character(rep(x[[keep]][i], length(x[[key1]][[i]])))})),
levels = levels(x[[keep]]))
} else{
vec = do.call("c", lapply(1:nrow(x),
function(i){ rep(x[[keep]][i], length(x[[key1]][[i]]))}))
}
return(vec)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment