?readline
Note that this gives you a character vector, so you might want to use
as.numeric() after that.
Petr
d. sarthi maheshwari napsal(a):
> Hi,
>
> I am trying to read some value from keyboard in one of my R program. I want
> to do manipulation on data based on this value. But I am facing a problem
> which is described below with the help of an example:
>
> My code is similar to:
>
> :
> :
> cat("\n","Enter value:: ","\n")
> y<-scan(n=1)
> a <- b*y
> cat("\n","Enter new value::","\n")
> y<-scan(n=1)
> :
> :
>
> Now if I run the whole script then something like this happens:
>
> :
> :
> cat("\n","Enter value::","\n")
>
> Enter value::
>> y<-scan(n=1)
> 1: a <- b*y
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
> :
> scan() expected 'a real', got 'a'
>> cat("\n","Enter new value::","\n")
>
> Enter new value::
>> y<-scan(n=1)
> 1: 2
> Read 1 item
> :
> :
>
> Is there any solution to this problem or shall I execute my script in two
> parts:
> First part:
>
> :
> :
> cat("\n","Enter value:: ","\n")
> y<-scan(n=1)
>
> and second part:
>
> a <- b*y
> cat("\n","Enter new value::","\n")
> y<-scan(n=1)
> :
> :
>
> Any help will be greatly appreciated.
--
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic
______________________________________________
[email protected] 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.