Thanks! This is helpful.
Three more questions.
1. How to convert a string into a numeric value. For
example, convert '20010122' to 20010122.
2. How to convert a string into a date value. For
example, convert 20010122
to 2001 Jan 22, and get its day of the week, i.e.
Monday?
3. How to handle date variables in a loop? How to make
the following codes work? And how users should pass
the date arguments to the function?
fun1 <- function(firstdate, lastdate) {
for ( i in firstdate:lastdate) {
do something....
}
}
fun1(2001/01/22, 2001/01/27)
--- Douglas Bates <bates at stat.wisc.edu> wrote:> Yu-Ling Wu <yuling5 at yahoo.com> writes:
>
> > I'd like to pass a string to a function as the
> value
> > of the argument.
> > Here is my code. However, it doesn't work. Please
> help
> > me with this.
> >
> > Thanks,
> > Yu-Ling Wu
> >
>
-----------------------------------------------------> > library(RODBC)
> > odbcConnect("console") -> myConnect
> >
> > fun1 <- function(dd1) {
> > h3 <- sqlQuery(myConnect, "select * from console
> where
> > byday = 'dd1'group by by hour")
> > }
>
> Use paste to construct a string from multiple input
> strings.
>
> sqlQuery(myConnect,
> paste("select * from console where byday
> =",
> dd1, "group by hour"))
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._