PNY
PNY

Reputation: 69

how to layout a data frame of many columns into a fitted layout in R

I have a data frame of 40 columns. I would like to export it into a Word file, but 40 columns can't fit into doc.page.

How can I make a layout with a layout of 10 columns at a time? I've tried split, but it did not work.

data

ID  age height  weight  class   graduate
1   42  167 54  1   yes
2   23  169 56  1   no
3   24  176 55  2   no
4   23  178 57  2   yes
5   25  158 56  3   yes
6   21  180 56  1   no
7   23  175 53  3   yes
8   23  166 49  3   no
9   22  167 60  2   no

new.data
ID  age height
1   42  167
2   23  169
3   24  176
4   23  178
5   25  158
6   21  180
7   23  175
8   23  166
9   22  167
weight  class   graduate
54  1   yes
56  1   no
55  2   no
57  2   yes
56  3   yes
56  1   no
53  3   yes
49  3   no
60  2   no

Upvotes: 0

Views: 71

Answers (1)

lmo
lmo

Reputation: 38500

Your question is not very clear, but to split your data.frame, into four columns of size ten, try the following:

df1 <- df[, 1:10]
df2 <- df[, 11:20]

You can select specific columns as well:

df3 <- df[, c(1,3,5,7,9)]

You can also write your data.frame to a .csv file and then format it in excel if that would be better. Use write.csv for that purpose.

Upvotes: 1

Related Questions