Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

How would one change this input (with the sequence: time, in, out, files):

Time   In    Out  Files

1      2     3    4

2      3     4    5

To this output (with the sequence: time, out, in, files)?

Time   Out   In  Files

1      3     2    4

2      4     3    5

Here's the dummy R data:

table <- data.frame(Time=c(1,2), In=c(2,3), Out=c(3,4), Files=c(4,5))

table

##  Time In Out Files

##1    1  2   3     4

##2    2  3   4     5

1 Answer

0 votes
by

To reorder columns of your data frame, run the following:

table[,c(1,3,2,4)]

The first comma means to include all the rows and the c(1,3,2,4) reorders the columns.

Output:

  Time Out In Files

1    1   3  2  4

2   2   4  3  5

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...