I want to repeat the lines of data.frame, every N times. The result should be a new data.frame (with nrow(new.df) == nrow(old.df) * N ) preserving the column data types.
Example for N = 2:
ABC ABC 1 ji 100 1 ji 100 --> 2 ji 100 2 KP 101 3 KP 101 4 KP 101
So, each line is repeated 2 times, and symbols remain symbols, factors remain factors, numerical values ββremain numbers, ...
My first attempt is used: apply(old.df, 2, function(co) rep(co, each = N)) , but this converts my values ββto characters, and I get:
ABC [1,] "j" "i" "100" [2,] "j" "i" "100" [3,] "K" "P" "101" [4,] "K" "P" "101"
r dataframe rows repeat
Stefan Jun 20 2018-12-12T00: 00Z
source share