Bhaskar Mitra
2017-Jun-26 02:35 UTC
[R] Request for help - adding text files to a data frame
Hello Everyone, I have a data frame which looks something like this: V1 <-c(1,2,3) V2 <-c(5,6,7) V3 <-c(9,10,11) df <- data.frame(V1,V2,V3) I want to add couple of text files at the beginning of df and save the df as a csv file. The csv file should look something like this: "AAAAAAAA" "BBBBBBBBB" "CCCCCCCCC" V1 V2 V3 1 5 9 2 6 10 3 7 11 Any suggestions/advice in this regard. Thanks for your help, Bhaskar [[alternative HTML version deleted]]
Bert Gunter
2017-Jun-26 05:50 UTC
[R] Request for help - adding text files to a data frame
You appear to either be ignorant of the structure pf data frames or have not expressed yourself clearly enough (for me, anyway). Please go through a tutorial to learn about the fixed structure of data frames, for which your request does not appear to reflect an understanding. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Jun 25, 2017 at 7:35 PM, Bhaskar Mitra <bhaskar.kolkata at gmail.com> wrote:> Hello Everyone, > > I have a data frame which looks something like this: > > V1 <-c(1,2,3) > V2 <-c(5,6,7) > V3 <-c(9,10,11) > > df <- data.frame(V1,V2,V3) > > I want to add couple of text files at the beginning of df and save > the df as a csv file. > > > The csv file should look something like this: > > "AAAAAAAA" > "BBBBBBBBB" > "CCCCCCCCC" > V1 V2 V3 > 1 5 9 > 2 6 10 > 3 7 11 > > > Any suggestions/advice in this regard. > > Thanks for your help, > Bhaskar > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
David Winsemius
2017-Jun-26 06:24 UTC
[R] Request for help - adding text files to a data frame
> On Jun 25, 2017, at 7:35 PM, Bhaskar Mitra <bhaskar.kolkata at gmail.com> wrote: > > Hello Everyone, > > I have a data frame which looks something like this: > > V1 <-c(1,2,3) > V2 <-c(5,6,7) > V3 <-c(9,10,11) > > df <- data.frame(V1,V2,V3) > > I want to add couple of text files at the beginning of df and save > the df as a csv file. > > > The csv file should look something like this: > > "AAAAAAAA" > "BBBBBBBBB" > "CCCCCCCCC" > V1 V2 V3 > 1 5 9 > 2 6 10 > 3 7 11Why exactly would that be called a csv file? (It has no commas.) At any rate discrepancies like that get resolved in favor of the example and my suggestion would be: First look carefully at: ?write.table # and read all the Arguments and Details sections ... as well as following all of the links from that help page that appear just above the Examples. write(c("AAAAAAAA", "BBBBBBBBB", "CCCCCCCCC"), file="test.txt") write.table(df, file="test.txt", append=TRUE,quote=FALSE,row.names=FALSE) rning message:> > > Any suggestions/advice in this regard. > > Thanks for your help, > Bhaskar > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.David Winsemius Alameda, CA, USA
Hi Bhaskar, You can put all sorts of stuff into a text file simply by using the "sink" command: sink("bm.txt") cat("AAAAAAAA\n") B9<-"BBBBBBBBB" cat(B9,"\n",sep="") for(i in 1:9) cat("C") cat("\n") print(df) sink() What you intend to do with a file like this is beyond me. Jim On Mon, Jun 26, 2017 at 12:35 PM, Bhaskar Mitra <bhaskar.kolkata at gmail.com> wrote:> Hello Everyone, > > I have a data frame which looks something like this: > > V1 <-c(1,2,3) > V2 <-c(5,6,7) > V3 <-c(9,10,11) > > df <- data.frame(V1,V2,V3) > > I want to add couple of text files at the beginning of df and save > the df as a csv file. > > > The csv file should look something like this: > > "AAAAAAAA" > "BBBBBBBBB" > "CCCCCCCCC" > V1 V2 V3 > 1 5 9 > 2 6 10 > 3 7 11 > > > Any suggestions/advice in this regard. > > Thanks for your help, > Bhaskar > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.