0
I have the following dataframe:
df <- data.frame(x1 = 1:7,x2 = 8:14, x3 = 15:21, x4 = 23:29, x5 = 30:36)
I need to replicate the value of each row 150, 100, 60, 43 times and for each column.
I tried to rep(df$x1, each=150)
, which replicates each line value 150 times but does not accept rep(df$x1, each=c(150,100,60,43))
... I thought to make through a loop with for for the lines of each column.
for(i in 1:ncol(df)) {
df$out[i] <- rep(df[,i])
for(i in 1:nrow(df)) {
df$out[i] <- rep(df[i,])
}
print(df$out)
}
However I’m not making any progress. Any suggestions?
You can provide an example of how you want the final result?
– Carlos Eduardo Lagosta