'Rowbinding all combinations of two vectors for each variation in a third vector
I have data as follows:
cat <- structure(c("east", "north", "south", "west"), .Dim = c(1L, 4L
), .Dimnames = list("categories", NULL))
down <- structure(c(0L, 25L, 50L, 100L, 250L, 500L, 1000L, 1500L, 3000L
), .Dim = c(1L, 9L), .Dimnames = list("lowers", NULL))
up <- structure(c(25L, 50L, 100L, 250L, 500L, 1000L, 1500L, 3000L,
1000000L), .Dim = c(1L, 9L), .Dimnames = list("uppers", NULL))
I would like to combine this data as follows:
cat east north south west east north south west
down 0 0 0 0 25 25 25 25
up 25 25 25 25 50 50 50 50
Altough it seems simple, I have no idea where to start..
Could someone point me in the right direction?
Solution 1:[1]
Maybe this helps
out <- rbind(rep(down, each = length(cat)), rep(up, each = length(cat)))
colnames(out) <- rep(c(cat), length.out = ncol(out))
row.names(out) <- c('down', 'up')
-output
> out
east north south west east north south west east north south west east north south west east north south west east north south west east north south west east
down 0 0 0 0 25 25 25 25 50 50 50 50 100 100 100 100 250 250 250 250 500 500 500 500 1000 1000 1000 1000 1500
up 25 25 25 25 50 50 50 50 100 100 100 100 250 250 250 250 500 500 500 500 1000 1000 1000 1000 1500 1500 1500 1500 3000
north south west east north south west
down 1500 1500 1500 3000 3000 3000 3000
up 3000 3000 3000 1000000 1000000 1000000 1000000
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | akrun |