I have a data.table:
library(data.table)
p1 = data.table(a = c(10.34,25.87,53.2), b=c(15.3,183.2,34.8))
print(p1)
a b
1: 10.34 15.3
2: 25.87 183.2
3: 53.20 34.8
What I would like to get is a new data.table with the following structure:
a b a1 b1 a2 b2 a3 b3
1: 10.34 15.3 10.34 15.3 25.87 183.2 53.2 34.8
2: 25.87 183.2 10.34 15.3 25.87 183.2 53.2 34.8
3: 53.20 34.8 10.34 15.3 25.87 183.2 53.2 34.8
My current solution is:
p2 = cbind(p,p[1,],p[2,],p[3,])
How do I create a similar (other than using for loops) data.table p2 with 10001 columns when I have input data.table p with 10000 rows?
Any help is appreciated.