anscombe, , @Thela reshape .
:
1: R
" ", , - :
myReshape <- function(indf = anscombe, stubs = c("x", "y")) {
temp <- sapply(stubs, function(x) {
unlist(indf[grep(x, names(indf))], use.names = FALSE)
})
s <- rep(seq_along(grep(stubs[1], names(indf))), each = nrow(indf))
data.frame(s, temp)
}
:
- , , , .
- , " " (, "x", "y".)
2: "dplyr" + "tidyr"
, :
library(dplyr)
library(tidyr)
anscombe %>%
gather(var, val, everything()) %>%
extract(var, into = c("variable", "s"), "(.)(.)") %>%
group_by(variable, s) %>%
mutate(ind = sequence(n())) %>%
spread(variable, val)
:
3: "splitstackshape"
, @Arun melt.data.table, merged.stack splitstackshape. :
library(splitstackshape)
setnames(
merged.stack(
data.table(anscombe, keep.rownames = TRUE),
var.stubs = c("x", "y"), sep = "var.stubs"),
".time_1", "s")[]
:
merged.stack - "id", , data.table(anscombe, keep.rownames = TRUE), "rn"sep = "var.stubs" , , , "time"merged.stack , . , anscombe2 <- anscombe[1:7] "anscombe".reshape, reshape, . , merged.stack. Reshape(data.table(anscombe, keep.rownames = TRUE), var.stubs = c("x", "y"), sep = ""), "time" setnames.
4: melt.data.table
, . R reshape , :
library(data.table)
melt(as.data.table(anscombe),
measure.vars = patterns(c("x", "y")),
value.name=c('x', 'y'),
variable.name = "s")
:
- .
- , "splitstackshape"
reshape; -) - .