David Kakauridze
David Kakauridze

Reputation: 315

Copy many columns from one data.frame to another

I have data.frame named test with 500 columns. I need to create the data.frame test1 with 7 columns, from test (their number is 1,2, 52, 121, 123, 344, 401 etc.) How can I do that easily? (I mean shortly )

Upvotes: 1

Views: 8589

Answers (1)

Matthew Lundberg
Matthew Lundberg

Reputation: 42689

A short example. Take columns 1,3 of a small data frame:

d <- data.frame(a=c(1,2,3), b=c(4,5,6), c=c(7,8,9),d=c(2,3,4))
d[,c(1,3)]

  a c
1 1 7
2 2 8
3 3 9

Upvotes: 12

Related Questions