r - Replicate rows and columns -


i have table contain text of information , need replicate each column 3 times

for example

a001 a002  a003 a004  

i want make

a001 a001 a001 a002 a002 a002  a003 a003 a003 a004 a004 a004  

is there way whole table?

you can repeat names of dataframe n (here 3) number of times using rep

rep(names(df), each=3)  #[1] "v1" "v1" "v1" "v2" "v2" "v2" 

and

df[rep(names(df), each = 3)]  #    v1 v1.1 v1.2   v2 v2.1 v2.2 #1 a001 a001 a001 a002 a002 a002 #2 a003 a003 a003 a004 a004 a004 

data

df <- structure(list(v1 = structure(1:2, .label = c("a001", "a003"),        class = "factor"),v2 = structure(1:2, .label = c("a002", "a004"),        class = "factor")), .names = c("v1","v2"), class = "data.frame",        row.names = c(na, -2l)) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -