[R] How to write to a table column by column?

Moshe Olshansky m_olshansky at yahoo.com
Wed Aug 15 09:34:44 CEST 2007


Hi Yuchen,

First of all please notice that you may not have more
than 2^8 = 256 columns in Excel, so if you have more
than 256 time-series you can not put them all in one
Excel sheet. I also believe that you can not have more
than 2^16 = 65536 rows.
If you do not have more than 256 time-series, I see
two possibilities.
The first one is to create a list which will hold all
your time-series (each list member holds one
time-series) and then make a double loop: one from 1
to as long as there is more data and if the first
variable is i you create a string by looping through
the list and adding to your string either element i
(and a tab) of time-series j if it's length is >= j or
a tab (and a tab) otherwise. Then you can write each
row to the file (using 'cat'). When you are done
import the resulting file into Excel.
Another possibility is to use xlsReadWritePro which
allows you to write to a specific column of a specific
sheet of an Excel file (and to append this).

Regards,

Moshe.

--- Yuchen Luo <realityrandom at gmail.com> wrote:

> Dear friends.
> Every loop of my program will result in a list that
> is very long, with a
> structure similar to the one below:
> 
> Lst <- list(name="Fred", wife="Mary",
> daily.incomes=c(1:850))
> 
> Please notice the large size of "daily.incomes".
> 
> I need to store all such lists in a csv file so that
> I can easily view them
> in Excel. Excel cannot display a row of more than
> 300 elements, therefore, I
> have to store the lists as columns. It is not hard
> to store one list as a
> column in the csv file. The problem is how to store
> the second list as a
> second column, so that the two columns will lie side
> by side to each other
> and I can easily compare their elements. ( If I use
> 'appened=TRUE', the
> second time series will be stored in the same
> column. )
> 
> Thank you for your tine and your help will be highly
> appreciated!!
> 
> Best
> 
> Yuchen Luo
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list