Hi everybody! I would like to export the results of a test statistic in a *.csv file, but get an error. The code is below. The data are attached as .txt with tab as separator. I tried to get a sample dataset, but for some reason it didn't work, so please excuse the length of the file. I also attached a txt with the output (copy/paste) in case that helps. ---- > library(WRS) > ssfamed <- read.table(file=file.choose(), header=T, sep="\t") > ssfa_Asfc <- fac2list(ssfa[,7], ssfa[3]) #store into list mode > test <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) #it takes about 5 seconds to run > write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F) Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, : arguments imply differing number of rows: 15, 6, 1 ---- I guess it is because of the formatting of the "test" object and I should reorganize it, but I actually have no idea how to do it. Tips would be greatly appreciated! Thanks in advance Ivan -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: output.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100204/a1b8bb1b/attachment.txt> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test_data.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100204/a1b8bb1b/attachment-0001.txt>
Is 'test' a dataframe? Provide the output of 'str(test)' and that will give an idea of what the structure is and maybe what you have to do to get it into a format for a csv file. On Thu, Feb 4, 2010 at 11:44 AM, Ivan Calandra <ivan.calandra at uni-hamburg.de> wrote:> Hi everybody! > > I would like to export the results of a test statistic in a *.csv file, but > get an error. > The code is below. > The data are attached as .txt with tab as separator. I tried to get a sample > dataset, but for some reason it didn't work, so please excuse the length of > the file. I also attached a txt with the output (copy/paste) in case that > helps. > > ---- >> library(WRS) >> ssfamed <- read.table(file=file.choose(), header=T, sep="\t") >> ssfa_Asfc <- fac2list(ssfa[,7], ssfa[3]) ?#store into list mode >> test <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) ?#it takes about >> 5 seconds to run >> write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F) > Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ?: > ?arguments imply differing number of rows: 15, 6, 1 > ---- > > I guess it is because of the formatting of the "test" object and I should > reorganize it, but I actually have no idea how to do it. > Tips would be greatly appreciated! > > Thanks in advance > Ivan > > > ______________________________________________ > 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 that you are trying to solve?
On Feb 4, 2010, at 11:44 AM, Ivan Calandra wrote:> Hi everybody! > > I would like to export the results of a test statistic in a *.csv > file, but get an error.What to you plan to do with this output file?> The code is below. > The data are attached as .txt with tab as separator. I tried to get > a sample dataset, but for some reason it didn't work, so please > excuse the length of the file. I also attached a txt with the output > (copy/paste) in case that helps. > > ---- > > library(WRS) > > ssfamed <- read.table(file=file.choose(), header=T, sep="\t") > > ssfa_Asfc <- fac2list(ssfa[,7], ssfa[3]) #store into list mode > > test <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) #it > takes about 5 seconds to run > > write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F) > Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, > 12, : > arguments imply differing number of rows: 15, 6, 1write.csv is for matrices, dataframes, and objects which can be coerced to dataframes. The result of a regression function would typically be a list that was way too irregular to be so coerced. You can see the organization f your "test" object with: str(test)> ---- > > I guess it is because of the formatting of the "test" object and I > should reorganize it, but I actually have no idea how to do it.Again. What is your goal? Perhaps: ?dump ?dput>-- David Winsemius, MD Heritage Laboratories West Hartford, CT
On 02/05/2010 03:44 AM, Ivan Calandra wrote:> Hi everybody! > > I would like to export the results of a test statistic in a *.csv file, > but get an error. > The code is below. > The data are attached as .txt with tab as separator. I tried to get a > sample dataset, but for some reason it didn't work, so please excuse the > length of the file. I also attached a txt with the output (copy/paste) > in case that helps. > > ---- > > library(WRS) > > ssfamed <- read.table(file=file.choose(), header=T, sep="\t") > > ssfa_Asfc <- fac2list(ssfa[,7], ssfa[3]) #store into list mode > > test <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) #it takes > about 5 seconds to run > > write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F) > Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, : > arguments imply differing number of rows: 15, 6, 1 > ---- > > I guess it is because of the formatting of the "test" object and I > should reorganize it, but I actually have no idea how to do it. > Tips would be greatly appreciated! >Hi Ivan, My guess is that you want to import this into a spreadsheet, the name of which I will not mention. If so, have a look at the delim.table function in the prettyR package. Jim
Hi r-help-bounces at r-project.org napsal dne 04.02.2010 17:44:05:> Hi everybody! > > I would like to export the results of a test statistic in a *.csv file, > but get an error. > The code is below. > The data are attached as .txt with tab as separator. I tried to get a > sample dataset, but for some reason it didn't work, so please excuse the> length of the file. I also attached a txt with the output (copy/paste) > in case that helps. > > ---- > > library(WRS) > > ssfamed <- read.table(file=file.choose(), header=T, sep="\t") > > ssfa_Asfc <- fac2list(ssfa[,7], ssfa[3]) #store into list mode > > test <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) #it takes > about 5 seconds to run > > write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F) > Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, : > arguments imply differing number of rows: 15, 6, 1 > ---- > > I guess it is because of the formatting of the "test" object and I > should reorganize it, but I actually have no idea how to do it.You can recognize structure of object by str(object)> Tips would be greatly appreciated!Structure of "test" output prevents to write test directly to csv. You could save it in several sub files, each part of the list to a single file. Regards Petr> > Thanks in advance > Ivan > > [p??loha output.txt odstran?na u?ivatelem Petr PIKAL/CTCAP] [p??loha > test_data.txt odstran?na u?ivatelem Petr PIKAL/CTCAP] > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Thanks to all for your help. So to answer all questions: - "test" is indeed a list. With my real data: > str(test) List of 3 $ output : num [1:15, 1:6] 1 2 3 4 5 6 7 8 9 10 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:6] "con.num" "psihat" "p.value" "p.crit" ... $ con : num [1:6, 1:15] 1 -1 0 0 0 0 1 0 -1 0 ... $ num.sig: int 0 - I want to export it to a csv file to save the results in a file that I will be able to edit. What I mean here is that for publications, I usually have the results from the statistic tests in a table. That is why I think that a csv file is the best option for me. However, I'm open to other suggestions! There might be better ways to save/store the results. - So what I do now is: > write.csv(test[[1]], file="pbmcp.csv", append=F, quote=F, row.names=F) > write.csv(test[[2]], file="pbmcp.csv", append=T, quote=F, row.names=T) > write.csv(test[[3]], file="pbmcp.csv", append=T, quote=F, row.names=F) I have then two other questions: - I would like the name of each element of the list to appear too. How should I do it? I can do: > write.csv(names(test)[[3]], file="pbmcp.csv", append=T, quote=F, row.names=F) But there might be an easier way. - It is not so complicated to run these lines, but I thought there might be a simpler and more compact way to do it. Thanks in advance for your help Ivan Le 2/5/2010 07:57, Rub?n Roa a ?crit :> > Or try > > write.csv(test, file="pbmcp.csv", append=F, quote=F, row.names=F, na='NA') > > HTH > ____________________________________________________________________________________ > > Dr. Rub?n Roa-Ureta > AZTI - Tecnalia / Marine Research Unit > Txatxarramendi Ugartea z/g > 48395 Sukarrieta (Bizkaia) > SPAIN > > > -----Mensaje original----- > De: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] En nombre de Jim Lemon > Enviado el: viernes, 05 de febrero de 2010 0:03 > Para: ivan.calandra at uni-hamburg.de > CC: r-help at r-project.org > Asunto: Re: [R] export test results to csv > > On 02/05/2010 03:44 AM, Ivan Calandra wrote: > >> Hi everybody! >> >> I would like to export the results of a test statistic in a *.csv >> file, but get an error. >> The code is below. >> The data are attached as .txt with tab as separator. I tried to get a >> sample dataset, but for some reason it didn't work, so please excuse >> the length of the file. I also attached a txt with the output >> (copy/paste) in case that helps. >> >> ---- >> > library(WRS) >> > ssfamed<- read.table(file=file.choose(), header=T, sep="\t")> >> ssfa_Asfc<- fac2list(ssfa[,7], ssfa[3]) #store into list mode> test >> <- pbmcp(ssfa_Asfc, alpha=0.05, nboot=2000, bhop=F) #it takes about 5 >> seconds to run> write.csv(test, file="pbmcp.csv", append=F, quote=F, >> row.names=F) Error in data.frame(output = c(1, 2, 3, 4, 5, 6, 7, 8, 9, >> 10, 11, 12, : >> arguments imply differing number of rows: 15, 6, 1 >> ---- >> >> I guess it is because of the formatting of the "test" object and I >> should reorganize it, but I actually have no idea how to do it. >> Tips would be greatly appreciated! >> >> > Hi Ivan, > My guess is that you want to import this into a spreadsheet, the name of which I will not mention. If so, have a look at the delim.table function in the prettyR package. > > Jim > > ______________________________________________ > 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. > >