Re: [R] Problem with sqlSave
Hi Karl, I was setting append=true because safer would delete the former datas when set to false. I must not have understood the purpose of these two attributes right. To be honest I tried all possible combinations and none would work. I am doing all this now with RExcel as I have been advised and it worked very well. Thank you for trying to help. Karl Ove Hufthammer wrote: On Thu, 19 Nov 2009 04:07:52 -0800 (PST) anna_l lippelanna21 @hotmail.com wrote: Hello, the sqlSave function is used in order to write a dataframe on excel. This function creates worksheets using the attribute tablename and writes the data.frame in it. What I want to do is to create this data.frame but being able in case this worksheet already exists to delete the former datas and write the new ones in it. I used the safer and append attributes. When you set safer to false, from what I understood, it should delete the former datas. Then what I did is setting safer as false and append as true so it can append to the empty dataframe the new dataframe but it didn?t work. Your question doesn't make sense. If you want to delete the older data, you should *not* use append = TRUE, since that is used only in the case that you want to append the new data to the old date. Since you *don't* want to retain the old data, why do you set append = TRUE? -- Karl Ove Hufthammer __ R-help@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. - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Problem-with-sqlSave-tp26421303p26441564.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Problem at adding lines on a graphics with lines() function
Hello, I am trying to plot a graphic with many lines with the following command: plot(datas[1:n,1],datas[1:n,2],type=l,main=SP500 Prices and Moving Averages,xlab=Date,ylab=Prices,col=black) lines(datas[1:n,1],datas[1:n,3],type=l,col=green,lty=solid) But I just see the first curve. I have tried it on the console separately and it´s still not working. There is no error message but I can´t see the second curve. Is there a parameter that I need to change with par()? Thank you - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Problem-at-adding-lines-on-a-graphics-with-lines%28%29-function-tp26443627p26443627.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Problem with sqlSave
Hello, the sqlSave function is used in order to write a dataframe on excel. This function creates worksheets using the attribute tablename and writes the data.frame in it. What I want to do is to create this data.frame but being able in case this worksheet already exists to delete the former datas and write the new ones in it. I used the safer and append attributes. When you set safer to false, from what I understood, it should delete the former datas. Then what I did is setting safer as false and append as true so it can append to the empty dataframe the new dataframe but it didn´t work. It appends in the existing worksheets but doesn´ t delete the existing datas. Any idea? - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Problem-with-sqlSave-tp26421303p26421303.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Problem on using Rexcel in the vba code
Hello everybody, I started to use Rexcel and I am getting an error with the following code: Sub AutoForma1_Clique() Call RInterface.StartRServer Call RInterface.RRun(setwd(C:/Program Files/R/R-2.10.0/Working Directory)) Call RInterface.RRun(getwd()) End Sub The error is the following when I run the macro: error in time execution '424', the object is obligatory Any idea? - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Problem-on-using-Rexcel-in-the-vba-code-tp26421377p26421377.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Problems by saving Rprofile.site under vista
Hello, I found a solution to the problem, quite easy. The R paste was on read-only, so I went to the properties/security. Apparently he considers me as a user and not an administrator when I open the files so I just gave the users ( me) the authorization to modificate and it worked. anna_l wrote: Hi Charles, I´ve already been running it as an administrator this is why I don´t understand it. Charles Annis, P.E. wrote: You may have to run R as Administrator (right-click, choose run as administrator) to make these kinds of changes. After you have things the way you like them, run R in the usual way by clicking on the icon. Charles Annis, P.E. charles.an...@statisticalengineering.com 561-352-9699 http://www.StatisticalEngineering.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of anna_l Sent: Friday, November 13, 2009 11:46 AM To: r-help@r-project.org Subject: [R] Problems by saving Rprofile.site under vista Hello, I am trying to save some changes I have done on the Rprofile.site under vista and it doesn´t let me save the file saying that it can´t create the following file (Rprofile.site) and that I should check the pathfile or the file name. -- View this message in context: http://old.nabble.com/Problems-by-saving-Rprofile.site-under-vista-tp26339605p26339605.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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. - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Problems-by-saving-Rprofile.site-under-vista-tp26339605p26408392.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Creating an excel file and manipulating it from R
Hello everybody, I´ve been looking for a function that would create an excel file in my working directory where I would write my dataframe but I only found the functions to write or read in an existing file that you gave me on my former post or on some websites. I can´t find either functions to manipulate those datas: for example, I would like some lines to be red or green according to their value. Thank you in advance! - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Creating-an-excel-file-and-manipulating-it-from-R-tp26408408p26408408.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Writing a data frame in an excel file
Hi Charlie, I´ve been trying to use the sqlSave the way you showed me but it would give me this error message which I couldn´t solve: Erro em sqlSave(xlsFile, strategy, tablename = Result, rownames = FALSE) : table ‘Result’ already exists I would like to save the data frame in a specified worksheet but I couldn´t find in the help on sqlSave how to do it. cls59 wrote: anna_l wrote: Hello, I am having trouble by using the write.table function to write a data frame of 4 columns and 7530 rows. I don´t know if I should just use a sep=\n and change the .xls file into a .csv file. Thanks in advance Base R cannot write .xls files by it's self. You should output CSV using write.csv(): write.csv( dataFrame, file = 'results.csv' ) If you are using R on windows, then the RODBC package provides a mechanism for dumping data frames directly to Excel files, possibly with multiple sheets: require( RODBC ) xlsFile - odbcConnectExcel( 'results.xls', readOnly = F ) sqlSave( xlsFile, dataFrame, tablename = 'R Results', rownames = F ) odbcCloseAll() The tablename argument to sqlSave allows you to assign a name to the excel sheet that will contain the data.frame. -Charlie - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26408412.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Writing a data frame in an excel file
Sorry Charlie, I didn´t understand that tablename=R Results was creating a worksheet. But the thing now is that it works very well when I write for the first time on the excel file but when I want to rewrite on it it gives the error i wrote before saying that Results already exists, is there a way to avoid that? - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26408421.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Writing a data frame in an excel file
Thanks Karl, well I am getting an error now after the following sqlSave command: sqlSave( xlsFile, datas, tablename = 'Datas_and_coefficients', rownames = FALSE ) -- [RODBC] Failed exec in Update 22018 39 [Microsoft][Driver ODBC for Excel]invalid character value for the diffusion specification (null) (null) More specifically, take a look at the 'append' and 'safer' arguments. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26412410.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Writing a data frame in an excel file
Ok I´ve been trying to understand what is happening: the data.frame I am sending on the xls file has been constructed by the following way: I used the RODBC package to read dates and prices columns into a dataframe so the first column in excel is of type date. In the data.frame it is not numeric but still double. So when I change the xls files I read by turning these dates datas into numbers, everything works well. So I don´t know if something has to be changed within the data.frame containing the dates or if I have to do everything in numbers and use RDCOM after to change the date column format of the excel file back into date type. anna_l wrote: Thanks Karl, well I am getting an error now after the following sqlSave command: sqlSave( xlsFile, datas, tablename = 'Datas_and_coefficients', rownames = FALSE ) -- [RODBC] Failed exec in Update 22018 39 [Microsoft][Driver ODBC for Excel]invalid character value for the diffusion specification (null) (null) More specifically, take a look at the 'append' and 'safer' arguments. -- Karl Ove Hufthammer __ R-help@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. - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26416861.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Simple if else statement problem
thanks petr, this is actually shorter ;) Petr Pikal wrote: Hi r-help-boun...@r-project.org napsal dne 13.11.2009 18:54:05: Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... you can use another approach in this case P-max(c(P1,P2)) Regards Petr anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement- problem-tp26340336p26340642.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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. -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26371185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Problems by saving Rprofile.site under vista
Hi Charles, I´ve already been running it as an administrator this is why I don´t understand it. Charles Annis, P.E. wrote: You may have to run R as Administrator (right-click, choose run as administrator) to make these kinds of changes. After you have things the way you like them, run R in the usual way by clicking on the icon. Charles Annis, P.E. charles.an...@statisticalengineering.com 561-352-9699 http://www.StatisticalEngineering.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of anna_l Sent: Friday, November 13, 2009 11:46 AM To: r-help@r-project.org Subject: [R] Problems by saving Rprofile.site under vista Hello, I am trying to save some changes I have done on the Rprofile.site under vista and it doesn´t let me save the file saying that it can´t create the following file (Rprofile.site) and that I should check the pathfile or the file name. -- View this message in context: http://old.nabble.com/Problems-by-saving-Rprofile.site-under-vista-tp26339605p26339605.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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. -- View this message in context: http://old.nabble.com/Problems-by-saving-Rprofile.site-under-vista-tp26339605p26371258.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Error on reading an excel file
Hello everybody, here is the code I use to read an excel file containing two rows, one of date, the other of prices: library(RODBC) z - odbcConnectExcel(SPX_HistoricalData.xls) datas - sqlFetch(z,Sheet1) close(z) It works pretty well but the only thing is that the datas stop at row 7530 and I don´t know why datas is a data frame that contains 7531 rows with the last two ones = NA... - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Error-on-reading-an-excel-file-tp26371750p26371750.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Error on reading an excel file
Thanks Charlie, well yes it included one row with two NA datas. I guess there is an explanation, let´s wait and see if someone knows more about it :) cls59 wrote: anna_l wrote: Hello everybody, here is the code I use to read an excel file containing two rows, one of date, the other of prices: library(RODBC) z - odbcConnectExcel(SPX_HistoricalData.xls) datas - sqlFetch(z,Sheet1) close(z) It works pretty well but the only thing is that the datas stop at row 7530 and I don´t know why datas is a data frame that contains 7531 rows with the last two ones = NA... I find this occurs sometimes when I export an Excel worksheet to CSV. Excel will include one or more rows of blank cells after the data stops. I would imagine the behavior you are seeing with RODBC is due to the same issue. I don't know if there is anything that can be done about it other than to trim your dataset back to the appropriate length once it gets into R. Good luck! -Charlie - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Error-on-reading-an-excel-file-tp26371750p26376656.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Writing a data frame in an excel file
Hello, I am having trouble by using the write.table function to write a data frame of 4 columns and 7530 rows. I don´t know if I should just use a sep=\n and change the .xls file into a .csv file. Thanks in advance - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378240.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Change working directory
Hello, I am using setwd() to change the working directory but I have to enter it everytime I open R, is there a way to set this permanently as a working directory? Thanx =^D -- View this message in context: http://old.nabble.com/Change-working-directory-tp26337486p26337486.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Problems by saving Rprofile.site under vista
Hello, I am trying to save some changes I have done on the Rprofile.site under vista and it doesn´t let me save the file saying that it can´t create the following file (Rprofile.site) and that I should check the pathfile or the file name. -- View this message in context: http://old.nabble.com/Problems-by-saving-Rprofile.site-under-vista-tp26339605p26339605.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Simple if else statement problem
Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26340336.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Simple if else statement problem
Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26340642.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Simple if else statement problem
ok thanks guys for the help, indeed I assumed there was an explanation thank you duncan for giving it! -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26343665.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Run an r file from the console
Hello everybody, I am writing an r file in the same R working directory and I would like to know how can I just run the whole file by just entering the file´s name on the console. I put the file in the working directory but it didn´t work saying that the file_name object wasn´t found. In matlab I could do this very simply, just write an m code and run it from the console by entering the file name. I´m new in R, thank you in advance :) -- View this message in context: http://old.nabble.com/Run-an-r-file-from-the-console-tp26323023p26323023.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.