library(dplyr)
df <- data.frame(z = rep(c("A", "B")), x = 1:6, y = 7:12) %>%
arrange(z)
temp <- reshape(df, v.names = c("x", "y"), idvar = c("x", "y"), timevar = "z",
direction = "wide")
lA <- na.omit(temp[,c("x.A", "y.A")])
lB <- na.omit(temp[,c("x.B", "y.B")])
df.long <- as.data.frame(cbind(lA,
Dear Michael,
You'll need a combination of dplyr and tidyr
library(dplyr)
library(tidyr)
data.frame(id = rep(1:3, 2), z = rep(c("A", "B")), x = 1:6, y = 7:12) %>%
arrange(z) %>%
gather(variable, value, -z, -id) %>%
mutate(newcol = paste(z, variable, sep = ".")) %>%
select(-z, -variable)
I have a data frame with a structure similar to the following. The variable
z is a grouping variable; x and y are measurement variables.
library(dplyr)
df <- data.frame(z = rep(c("A", "B")), x = 1:6, y = 7:12) %>%
arrange(z)
z x y
1 A 1 7
2 A 3 9
3 A 5 11
4 B 2 8
5 B 4 10
6 B 6 12
I nee
3 matches
Mail list logo