I have the following data.frame data:
data <- data.frame(matrix(0, ncol=4, nrow=4))
colnames <- seq(from = 6, to = 3, by = -1)
names(data)<- sprintf("%.1f", colnames)
rownames <- seq(from=5, to=2, by=-1)
rownames(data) <- sprintf("%.0f", rownames)
I have two vectors, a and b:
a <- seq(11, 5, -1)
b <- seq(0, 30, 5)
a represents all possible sums that the column and row headers can take. For example, the northwest-most cell is 6+5=11.
b represents the values that I want to be filled into the data.frame. The order corresponds to the order of a. For example, data[1,1] (row and column names sum to 11) should take on value 0. data[1,2] and data[2,1] should both take on value 5.
How would I go about doing this?
Aucun commentaire:
Enregistrer un commentaire