Hi All,
I need a basic help from you. I've built a function like this,
windowlength<-function(x)
{
z <- rep(seq(0,331,by=x-1)+1, each=2)
zz <- z[-c(1,length(z))]
ind <- as.data.frame(matrix(zz, nr=2))
j<-lapply(ind, function(x) mat[x[1]:x[2],])
cat("For",x/4,"month number of windows is =
",length(ind),"\n")
}
windowlength(x=12)
I need to know how can i give command in "R" so that instead of giving
the last line, i.e "R" will ask the user to give the value of x? I
mean to say,
1) It will ask user "Give the value of x"
2) Then user inputs 12, and R gives the ultimate result.
Thanks,
Sumanta Basak.
---------------------------------
What makes Sachin India's highest paid sports celebrity?, Share your
knowledge on Yahoo! India Answers
Send instant messages to your online friends - NOW
[[alternative HTML version deleted]]
On Fri, 12 May 2006, SUMANTA BASAK wrote:> I need a basic help from you. I've built a function like this, > > windowlength<-function(x) > { > z <- rep(seq(0,331,by=x-1)+1, each=2) > zz <- z[-c(1,length(z))] > ind <- as.data.frame(matrix(zz, nr=2)) > j<-lapply(ind, function(x) mat[x[1]:x[2],]) > cat("For",x/4,"month number of windows is = ",length(ind),"\n") > } > windowlength(x=12) > > I need to know how can i give command in "R" so that instead of giving the last line, i.e "R" will ask the user to give the value of x? I mean to say, > 1) It will ask user "Give the value of x" > 2) Then user inputs 12, and R gives the ultimate result.as.numeric(readline("Give the value of x: ")) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Use readline.
x <- readline("Give the value of x? ")
cat("The value of x is", x, "\n")
Cheers,
Simon.
SUMANTA BASAK wrote:> Hi All,
>
> I need a basic help from you. I've built a function like this,
>
> windowlength<-function(x)
> {
> z <- rep(seq(0,331,by=x-1)+1, each=2)
> zz <- z[-c(1,length(z))]
> ind <- as.data.frame(matrix(zz, nr=2))
> j<-lapply(ind, function(x) mat[x[1]:x[2],])
> cat("For",x/4,"month number of windows is =
",length(ind),"\n")
> }
> windowlength(x=12)
>
> I need to know how can i give command in "R" so that instead of
giving the last line, i.e "R" will ask the user to give the value of
x? I mean to say,
> 1) It will ask user "Give the value of x"
> 2) Then user inputs 12, and R gives the ultimate result.
>
> Thanks,
> Sumanta Basak.
>
>
> ---------------------------------
> What makes Sachin India's highest paid sports celebrity?, Share your
knowledge on Yahoo! India Answers
> Send instant messages to your online friends - NOW
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>
--
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C