I'm trying to simulate data for an experiment (learning purpose, self-taught) The purpose is to see how with the increase of distance (in cm) my variable decrease (I'm actually expecting that with the real data the decrease will be not linear). 5 replicate generated around my expected value, each indicated as e1, e2 etc.. and 4 distances indicated in cm
So this is the matrix:
dis2 <- rnorm(5, mean = 0.25, sd = 0.01)
dis12 <- rnorm(5, mean = 0.22, sd = 0.01)
dis24 <- rnorm(5, mean = 0.19, sd = 0.01)
dis36 <- rnorm(5, mean = 0.16, sd = 0.01)
mat <- matrix(c(dis2, dis12, dis24, dis36), ncol=5, byrow = TRUE)
tmat <- t(mat)
dfmat <- as.data.frame(tmat)
colnames(dfmat) <- c("2cm", "12cm", "24cm", "36cm")
rownames(dfmat) <- c("e1", "e2", "e3", "e4", "e5")
Now I want to build a 3 column dataframe where each measure has the value but also if those values belong to e1, e2 etc.. and if the measure is relative to 2cm, 12 cm etc
The closest I could come is by melt()
list <- as.list(dfmat)
melted <- melt(list)
Here I can obtain the respective distance and value measure but not at which experiment (e1, e2 etc..) belong
How can I add this parameter? I've tried to add the (e1, e2 etc..) as a factor but still can not manage to melt the list correctly
Any help would be great