[R] Migrating from S-Plus to R - Exporting Tables

jim holtman jholtman at gmail.com
Thu Jul 3 02:17:14 CEST 2008


Does something like this get you close:

x <- list()
keys <- LETTERS[1:6]
# create
for (i in keys){
    x[[i]] <- data.frame(a=1:5, b=1:5, c=1:5)
}
# output
output <- file('tempxx.txt', 'w')
for (i in keys){
    write.table(i, row.names=FALSE, col.names=FALSE, file=output, quote=FALSE)
    write.table(x[[i]], file=output, quote=FALSE)
}
close(output)



On Wed, Jul 2, 2008 at 12:15 PM, Leandro Marino
<leandro at cesgranrio.org.br> wrote:
> I am puting again without some columns.
>
> The questgeral it is a list that have this layout:
>
> questimp[[1]]
>  Num   Perc  media stdev   min     P5    P10    P25    P50    P75    P90
> 1   12418  58.00 183.71 37.28 86.98 126.11 138.11 157.58 180.95 207.55
> 233.76
> 2    4898  22.88 188.45 38.79 86.98 128.89 140.62 160.69 185.38 214.12
> 241.36
> 3    2161  10.09 188.22 39.38 87.13 126.97 138.63 159.67 186.76 212.59
> 241.15
> 4    1934   9.03 175.70 34.59 86.98 122.76 133.00 152.29 172.40 198.13
> 220.71
> tot 21411 100.00 184.53 37.77 86.98 126.52 138.22 157.85 181.75 208.82
> 235.51
>       P95    max
> 1   249.24 354.49
> 2   256.39 344.28
> 3   256.44 352.71
> 4   237.78 317.62
> tot 251.35 354.49
>
> and nomequest is a vector
>> nomequest04
>  [1] "Q05"    "Q06"    "Q07"    "Q08"    "Q09"    "Q10"    "Q11"    "Q12"
>  [9] "Q14"    "Q15"    "NESCPM"
>
>
>
>
>
>
> I want to export an table using the write.table and i want is this format:
> (this table was exported in s-plus)
>
> Q01
> row.names       Num     Perc    meab    stdev   min
> A               10237   47.88   183.48  38.84   86.98
> B               10243   47.91   186.91  36.55   86.98
>                762     3.56    178.73  36.37   90.19
> *               137     0.64    150.77  32.88   96.42
> tot             21379   100     182.48  37.77   86.98
>
> It is a lot of tables, in S-plus I was using
>
> for (i in 1:length(nrotulos)) {
> write.table(nomequest[i],
> "Y:\\questgeral.txt",sep="\t",append=T)
> write.table(questgeral[[i]],
> "Y:\\questgeral.txt",sep="\t",dimnames.write=T,append=T)
> }
>
> Now, i am trying to do the same thing in R. But, I have a lot of warnings
> and the result is:
> x
> 1       Q05
> Num     Perc    media   stdev   min
> 1       12418   58      183.71  37.28   86.98
> 2       4898    22.88   188.45  38.79   86.98
> 3       2161    10.09   188.22  39.38   87.13
> 4       1934    9.03    175.7         34.59     86.98
> tot     21411   100     184.53  37.77   86.98
>
> using this code:
> for (i in 1:length(nrotulos04)) {
> write.table(nomequest[i],
> "Y:/questimp1104m.txt",dec=".",sep=";",append=T,quote=F)
> write.table(questimp[[i]],
> "Y:/questimp1104m.txt",dec=".",sep=";",append=T,quote=F)
> }
>
>
> How can I put the row.names before the col num in R? And how can I remove
> the x in first line and the number 1 and the ^t in the second line before
> Q05?
>
> Thanks for the advance!
>
> Leandro Marino
> -----Mensagem original-----
> De: jim holtman [mailto:jholtman at gmail.com]
> Enviada em: quarta-feira, 2 de julho de 2008 12:47
> Para: Leandro Marino
> Assunto: Re: [R] Migrating from S-Plus to R - Exporting Tables
>
>
> It is hard to tell without providing commented, minimal,
> self-contained, reproducible code.  We need to see the data you are
> writing out.  You can save the first 10, or so, lines of input with
>
> dput(yourData[1:10,])
>
> and then sending the file.  Trying to read tables in email is hard.
> You are also appending output from possibily two different table sizes
> which also may be causing the problem.  We need data to analyze what
> is happening.
>
> On Wed, Jul 2, 2008 at 10:06 AM, Leandro Marino
> <leandro at cesgranrio.org.br> wrote:
>>
>> Hi,
>>
>> I want to export an table using the write.table and i want is this format:
>> (this table was exported in s-plus)
>>
>> Q01
>> row.names       Num     Perc    meab    stdev   min     P5      P10
> P25     P50     P75
>> P90     P95     max
>> A               10237   47.88   183.48  38.84   86.98   126.52  138.13
> 157.82  182.41  210.17
>> 238.94  254.13  354.49
>> B               10243   47.91   186.91  36.55   86.98   128.18  139.96
> 159.27  182.42  208.75
>> 233.2   249.07  336.17
>>                762     3.56    178.73  36.37   90.19   114.27  127.16
> 144.88  166.59  193.56
>> 220.37  234.42  307.87
>> *               137     0.64    150.77  32.88   96.42   112.72  120.59
> 139.84  159.36  181.25
>> 206.01  216.33  254.58
>> tot             21379   100     182.48  37.77   86.98   126.52  138.22
> 157.85  181.75  208.82
>> 235.51  251.35  354.49
>>
>> It is a lot of tables, in S-plus I was using
>>
>> for (i in 1:length(nrotulos)) {
>> write.table(nomequest[i],
>> "Y:\\questgeral.txt",sep="\t",append=T)
>> write.table(questgeral[[i]],
>> "Y:\\questgeral.txt",sep="\t",dimnames.write=T,append=T)
>> }
>>
>> Now, i am trying to do the same thing in R. But, I have a lot of warnings
>> and the result is:
>> x
>> 1       Q05
>> Num     Perc    media   stdev   min     P5      P10     P25     P50
> P75     P90     P95     max
>> 1       12418   58      183.71  37.28   86.98   126.11  138.11  157.58
> 180.95  207.55  233.76
>> 249.24  354.49
>> 2       4898    22.88   188.45  38.79   86.98   128.89  140.62  160.69
> 185.38  214.12  241.36
>> 256.39  344.28
>> 3       2161    10.09   188.22  39.38   87.13   126.97  138.63  159.67
> 186.76  212.59  241.15
>> 256.44  352.71
>> 4       1934    9.03    175.7         34.59     86.98   122.76  133
> 152.29  172.4           198.13  220.71
>> 237.78  317.62
>> tot     21411   100     184.53  37.77   86.98   126.52  138.22  157.85
> 181.75  208.82  235.51
>> 251.35  354.49
>>
>> using this code:
>> for (i in 1:length(nrotulos04)) {
>> write.table(nomequest[i],
>> "Y:/questimp1104m.txt",dec=".",sep=";",append=T,quote=F)
>> write.table(questimp[[i]],
>> "Y:/questimp1104m.txt",dec=".",sep=";",append=T,quote=F)
>> }
>>
>>
>> How can I put the row.names before the col num in R? And how can I remove
>> the x in first line and the number 1 and the ^t in the second line before
>> Q05?
>>
>> Thanks for the advance!
>>
>> Leandro Marino
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
>
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list