Displaying 1 result from an estimated 1 matches for "y41".
Did you mean:
41
2004 Sep 14
3
reshaping some data
...low and not very efficient. I would like to find a vectorised
solution that would achieve the same thing.
Now, for an example:
x <- data.frame(x1 = 1: 5, y11 = 1: 5,
x2 = 6:10, y21 = 6:10, y22 = 11:15,
x3 = 11:15, y31 = 16:20,
x4 = 16:20, y41 = 21:25, y42 = 26:30, y43 = 31:35)
# which are the x columns
nmx <- grep("^x", names(x))
# which are the y columns
nmy <- grep("^y", names(x))
# grab y values
y <- unlist(x[nmy])
# reserve some space for the x's
z <- vector("numeric", length(y))
# a loo...