[R] write.table a df with specific column order

Don MacQueen macq at llnl.gov
Thu Jun 26 16:29:05 CEST 2008


Minor correction -- omitted comma. Should be:

    write.table(t[ , c("a", "b", "c")], row.names=FALSE)

Also, using the name "t" should be avoided, 
because "t" is a built-in function:  t()

-Don

At 8:02 AM -0300 6/26/08, Henrique Dallazuanna wrote:
>Content-Type: text/plain
>Content-Disposition: inline
>Content-length: 919
>
>Try:
>
>write.table(t[c("a", "b", "c")], row.names=F)
>
>On Thu, Jun 26, 2008 at 6:28 AM, juli pausas <pausas at gmail.com> wrote:
>
>>  Hi
>>  I'd like to write.table a dataframe, but with an specific order of
>>  columns. Is there a direct way to do it? or I have to generate a new
>>  dataframe as follows:
>>
>>  t  <- data.frame(c=1:10, b=11:20, a=letters[1:10])
>>  t2 <- data.frame(a=t$a, b=t$b, c=t$c)
>>  write.table(t2, row.names=F)
>>
>>  Thanks for any comment
>>
>>  Juli
>>
>>  --
>>  http://www.ceam.es/pausas
>>
>>  ______________________________________________
>>  R-help at r-project.org mailing list
>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>  PLEASE do read the posting guide
>>  http://www.R-project.org/posting-guide.html
>>  and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
>--
>Henrique Dallazuanna
>Curitiba-Paraná-Brasil
>25° 25' 40" S 49° 16' 22" O
>
>	[[alternative HTML version deleted]]
>
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-help mailing list