I'm new to R and trying to make my life easier.I have a dataframe with several columns that will vary in size. Mainly it will be a 'gene' column and the rest will be expression numeric data for different patients/conditions. I want 1) sort by each of the numeric columns and 2) create files that include only the 'gene' column and each numeric column. I'm trying to generate a for loop for this. Using the mtcars built in database as an example I generated the following code:

```
mtcars

for (i in 2:ncol(mtcars)) {
  twocolumns <- data.frame(mtcars[,c(1,i)])
  write.csv(twocolumns, paste0(i,'.txt'), row.names = F)
}

```

this creates files with the names 1,2,3,4... '.txt'. How do I make these so they have the same name as the columns?

Also I haven't figured out the sorting part. So far i've tried this

```
mtcars <- mtcars[order(i),]

```

(Right before the 'twocolumns' line but this creates 1 row, 2 column files. )

Any help will be appreciated!