i want to print in the console and to have an excel file like this
no_GWP NbOfPolicyClass1[0-1000]
NbOfPolicyClass2[1000-3000] NbOfPolicyClass3[> 3000]
No_GWPMax=8 NbpolicyClass1=5
NbpolicyClass2=4 NbpolicyClass3 =3
i have do it like this:!!!
data1 <-
read.csv2("c:/Total1.csv",sep=",")> data2 <- read.csv2("c:/GWPMax1.csv",sep=",")
> M <- merge(data1, data2, by.x = "Policy.Number", by.y =
"Policy.Number")
> nrow(data1)
[1] 20> nrow(M)
[1] 12> No_GWPMax <- nrow(data1)-nrow(M)
> (NbOfPolicyWithoutGWPMax <- nrow(data1)-nrow(M))
[1] 8> M$GWP_Max <- as.numeric(as.character(M$GWP_Max))
> class1 <- M[(M[,25]> 0 & M[,25]<1000) ,]
> NbpolicyClass1 <- nrow(class1)
> class2<- K[(K[,25]>1000 & K[,25]<3000),]
> NbpolicyClass2 <- nrow(class2)
> class3 <- K[(K[,25]>3000),]
> NbpolicyClass3 <- nrow(class3)
> Output<- "No_GWPMax
,NbpolicyClass1[0-1000],NbpolicyClass2[1000-3000],NbpolicyClass3[>3000]"
> Output <- paste(No_GWPMax
,NbpolicyClass1,NbpolicyClass2,NbpolicyClass3,sep=",")
> cat(Output,file="Output2.csv",fill=TRUE,append=TRUE)
but that doesn't give me the title juste 8 5 4 3
any ideas??
thank you a lot
[[alternative HTML version deleted]]
Output write.xls( x, file ="my.file") --- On Mon, 8/10/09, Inchallah Yarab <inchallahyarab at yahoo.fr> wrote:> From: Inchallah Yarab <inchallahyarab at yahoo.fr> > Subject: [R] how use cat() function? > To: r-help at r-project.org > Received: Monday, August 10, 2009, 12:06 PM > i? want to print in the console and > to have an excel file like this > > no_GWP?????????????? > ?NbOfPolicyClass1[0-1000]???? > NbOfPolicyClass2[1000-3000]??????? > NbOfPolicyClass3[> 3000] > No_GWPMax=8????NbpolicyClass1=5?????????????????? > NbpolicyClass2=4??????????????????????????? > NbpolicyClass3 =3????????????? > > i have do it like this:!!! > data1 <- read.csv2("c:/Total1.csv",sep=",") > > data2 <- read.csv2("c:/GWPMax1.csv",sep=",") > > M <- merge(data1, data2, by.x = "Policy.Number", > by.y = "Policy.Number") > > nrow(data1) > [1] 20 > > nrow(M) > [1] 12 > > No_GWPMax <- nrow(data1)-nrow(M) > > (NbOfPolicyWithoutGWPMax <- nrow(data1)-nrow(M)) > [1] 8 > > M$GWP_Max <- as.numeric(as.character(M$GWP_Max)) > > class1 <- M[(M[,25]> 0 & M[,25]<1000) ,] > > NbpolicyClass1 <- nrow(class1) > > class2<- K[(K[,25]>1000 & K[,25]<3000),] > > NbpolicyClass2 <-? nrow(class2) > > class3 <- K[(K[,25]>3000),] > > NbpolicyClass3 <- nrow(class3) > > Output<- "No_GWPMax > ,NbpolicyClass1[0-1000],NbpolicyClass2[1000-3000],NbpolicyClass3[>3000]" > > Output <- paste(No_GWPMax > ,NbpolicyClass1,NbpolicyClass2,NbpolicyClass3,sep=",") > > cat(Output,file="Output2.csv",fill=TRUE,append=TRUE) > > but that doesn't give me the title juste 8 5 4 3 > > any ideas?? > > thank you a lot > > > ? ? ? > ??? [[alternative HTML version deleted]] > > > -----Inline Attachment Follows----- > > ______________________________________________ > 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. >__________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/
I'm not exactly sure how you want the file to look, but try this code and
see if it works for you.
# since I don't have the data file, I'll just set the values here
No_GWPMax <- 8
NbpolicyClass1 <- 5
NbpolicyClass2 <- 4
NbpolicyClass3 <- 3
# output1 is the first row of headers
Output1 <- paste("No_GWPMax", "NbpolicyClass1[0-1000]",
"NbpolicyClass2[1000-3000]", "NbpolicyClass3[>3000]",
sep=",")
# output2 is the second row of values
Output2 <- paste("No_GWPMax=", No_GWPMax,
",NbpolicyClass1=",
NbpolicyClass1, ",NbpolicyClass2=", NbpolicyClass2,
",NbpolicyClass3=", NbpolicyClass3, sep="")
# save the two output rows to a csv file
cat(Output1, file="Output2.csv", fill=TRUE, append=TRUE)
cat(Output2, file="Output2.csv", fill=TRUE, append=TRUE)
---
From: Inchallah Yarab <inchallahyarab <at> yahoo.fr>
Subject: how use cat() function?
Newsgroups: gmane.comp.lang.r.general
Date: 2009-08-10 16:06:10 GMT (2 hours and 29 minutes ago)
i want to print in the console and to have an excel file like this
no_GWP NbOfPolicyClass1[0-1000]
NbOfPolicyClass2[1000-3000] NbOfPolicyClass3[> 3000]
No_GWPMax=8 NbpolicyClass1=5
NbpolicyClass2=4 NbpolicyClass3
=3
i have do it like this:!!!
data1 <-
read.csv2("c:/Total1.csv",sep=",")> data2 <- read.csv2("c:/GWPMax1.csv",sep=",")
> M <- merge(data1, data2, by.x = "Policy.Number", by.y =
"Policy.Number")
> nrow(data1)
[1] 20> nrow(M)
[1] 12> No_GWPMax <- nrow(data1)-nrow(M)
> (NbOfPolicyWithoutGWPMax <- nrow(data1)-nrow(M))
[1] 8> M$GWP_Max <- as.numeric(as.character(M$GWP_Max))
> class1 <- M[(M[,25]> 0 & M[,25]<1000) ,]
> NbpolicyClass1 <- nrow(class1)
> class2<- K[(K[,25]>1000 & K[,25]<3000),]
> NbpolicyClass2 <- nrow(class2)
> class3 <- K[(K[,25]>3000),]
> NbpolicyClass3 <- nrow(class3)
> Output<- "No_GWPMax
,NbpolicyClass1[0-1000],NbpolicyClass2[1000-3000],NbpolicyClass3[>3000]"> Output <- paste(No_GWPMax
,NbpolicyClass1,NbpolicyClass2,NbpolicyClass3,sep=",")> cat(Output,file="Output2.csv",fill=TRUE,append=TRUE)
but that doesn't give me the title juste 8 5 4 3
any ideas??
thank you a lot
[[alternative HTML version deleted]]
Here is are some examples that might help.
a <- 1
b <- 2
c <- 5
cat( "a=,",a, " b=,",b, " c=",c, "\n"
, sep='', file="output.csv")
and don't append unless you are adding more lines to an existing file.
Or perhaps you want
cat("a,b,c\n",file="output.csv")
cat( paste( a,b,c , collapse=",") ,"/n" ,
file="output.csv", append=TRUE)
Yet, you are using sep="," in your code, but you show no commas
in your example of what you want.
So perhaps
cat("a b c\n",file="output.csv")
cat( "a=,",a, " b= ,",b, " c=",c,
"\n" , sep='', file="output.csv")
or
output <- paste( "a=,",a, " b= ,",b, "
c=",c, sep='')
cat(output, '\n', file="output.csv", append=TRUE)
-Don
At 4:06 PM +0000 8/10/09, Inchallah Yarab wrote:>Content-Type: text/plain
>Content-Disposition: inline
>Content-length: 1497
>
>i want to print in the console and to have an excel file like this
>
>no_GWP NbOfPolicyClass1[0-1000]
>NbOfPolicyClass2[1000-3000] NbOfPolicyClass3[> 3000]
>No_GWPMax=8 NbpolicyClass1=5 NbpolicyClass2=4
>NbpolicyClass3 =3
>
>i have do it like this:!!!
>data1 <- read.csv2("c:/Total1.csv",sep=",")
>> data2 <- read.csv2("c:/GWPMax1.csv",sep=",")
>> M <- merge(data1, data2, by.x = "Policy.Number", by.y =
"Policy.Number")
>> nrow(data1)
>[1] 20
>> nrow(M)
>[1] 12
>> No_GWPMax <- nrow(data1)-nrow(M)
>> (NbOfPolicyWithoutGWPMax <- nrow(data1)-nrow(M))
>[1] 8
>> M$GWP_Max <- as.numeric(as.character(M$GWP_Max))
>> class1 <- M[(M[,25]> 0 & M[,25]<1000) ,]
>> NbpolicyClass1 <- nrow(class1)
>> class2<- K[(K[,25]>1000 & K[,25]<3000),]
>> NbpolicyClass2 <- nrow(class2)
>> class3 <- K[(K[,25]>3000),]
>> NbpolicyClass3 <- nrow(class3)
> > Output<- "No_GWPMax
>,NbpolicyClass1[0-1000],NbpolicyClass2[1000-3000],NbpolicyClass3[>3000]"
>> Output <- paste(No_GWPMax
>>,NbpolicyClass1,NbpolicyClass2,NbpolicyClass3,sep=",")
> > cat(Output,file="Output2.csv",fill=TRUE,append=TRUE)
>
>but that doesn't give me the title juste 8 5 4 3
>
>any ideas??
>
>thank you a lot
>
>
>
> [[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