Re: [R] help with function system and MS-DOS command TYPE

2007-01-31 Thread Vladimir Eremeev


Chen, Xiao wrote:
 
 Greetings -
 
 I have a quick question that I hope someone will have a quick answer. I
 have tried to use the R function system with the MS-DOS command type
 to display the full content of a text file. But it always returns with a
 message saying the text file is not found. I could accomplish the same 
 task with the cat command which is one of the unix-like commands that 
 I have installed on my windows machine. But I would like to know how it 
 would work with the type command.  
 
 Here is what I have tried:
 
 zz-file(d:/work/test/test.txt, w)
 cat(this is a test\n, file=zz)
 close(zz)
 system(cat test.txt, show.output.on.console=T)
 this is a test
 system(type test.txt, show.output.on.console=T)
 test.txt not found
 

type is an internal command, rather than an executable file

use
system(cmd /c type test.txt, show.output.on.console=T)
or
system(command /c type test.txt, show.output.on.console=T)

-- 
View this message in context: 
http://www.nabble.com/-R--help-with-function-%22system%22-and-MS-DOS-command-TYPE-tf3146629.html#a8727428
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with function system and MS-DOS command TYPE

2007-01-31 Thread jim holtman
Try 'file.show'

On 1/30/07, Chen, Xiao [EMAIL PROTECTED] wrote:
 Greetings -

 I have a quick question that I hope someone will have a quick answer. I
 have tried to use the R function system with the MS-DOS command type
 to display the full content of a text file. But it always returns with a
 message saying the text file is not found. I could accomplish the same
 task with the cat command which is one of the unix-like commands that
 I have installed on my windows machine. But I would like to know how it
 would work with the type command.

 Here is what I have tried:

  zz-file(d:/work/test/test.txt, w)
  cat(this is a test\n, file=zz)
  close(zz)
  system(cat test.txt, show.output.on.console=T)
 this is a test
  system(type test.txt, show.output.on.console=T)
 test.txt not found
 


 Thanks much for any help that you could offer.

 Best,

 Xiao Chen
 Statistical Consulting Group
 UCLA Academic Technology Services
 http://www.ats.ucla.edu/stat/

 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with function system and MS-DOS command TYPE

2007-01-31 Thread Prof Brian Ripley
On Wed, 31 Jan 2007, Vladimir Eremeev wrote:

 Chen, Xiao wrote:

 Greetings -

 I have a quick question that I hope someone will have a quick answer. I
 have tried to use the R function system with the MS-DOS command type
 to display the full content of a text file. But it always returns with a
 message saying the text file is not found. I could accomplish the same
 task with the cat command which is one of the unix-like commands that
 I have installed on my windows machine. But I would like to know how it
 would work with the type command.

 Here is what I have tried:

 zz-file(d:/work/test/test.txt, w)
 cat(this is a test\n, file=zz)
 close(zz)
 system(cat test.txt, show.output.on.console=T)
 this is a test
 system(type test.txt, show.output.on.console=T)
 test.txt not found


 type is an internal command, rather than an executable file

 use
 system(cmd /c type test.txt, show.output.on.console=T)
 or
 system(command /c type test.txt, show.output.on.console=T)

or use the user-friendly version shell(), as it says on the help page for 
system() (together with a portable version of the above).

Please can people who answer questions do their homework as the posting 
guide requests, and point to the definitive documentation.  The archives 
of these lists are a public resource, and often searched to pick up
pieces of misinformation.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with function system and MS-DOS command TYPE

2007-01-31 Thread Chen, Xiao
Dear R-Help,

Thanks much. 

I have received very good advice from a couple of experts.  R-help is
just wonderful!

I have combined all the solutions that I got and they are shown below:

zz-file(d:/work/test/test.txt, w) 
cat(this is a test\n, file=zz)
close(zz)

setwd(d:/work/test)
shell(type test.txt) 
system(cat test.txt, show.output.on.console=T)
file.show(d:/work/test/test.txt) #opens a new window
file.show(d:/work/test/test.txt, pager=console) #displays on console

Thanks again for all the help. 

Best regards,

Xiao Chen
Statistical Consulting Group
UCLA Academic Technology Services
http://www.ats.ucla.edu/stat/

-Original Message-
From: Chen, Xiao 
Sent: Tuesday, January 30, 2007 8:23 PM
To: 'r-help@stat.math.ethz.ch'
Subject: help with function system and MS-DOS command TYPE

Greetings -

I have a quick question that I hope someone will have a quick answer. I
have tried to use the R function system with the MS-DOS command type
to display the full content of a text file. But it always returns with a
message saying the text file is not found. I could accomplish the same
task with the cat command which is one of the unix-like commands that
I have installed on my windows machine. But I would like to know how it
would work with the type command.  

Here is what I have tried:

 zz-file(d:/work/test/test.txt, w)
 cat(this is a test\n, file=zz)
 close(zz)
 system(cat test.txt, show.output.on.console=T)
this is a test
 system(type test.txt, show.output.on.console=T)
test.txt not found



Thanks much for any help that you could offer. 

Best, 

Xiao Chen
Statistical Consulting Group
UCLA Academic Technology Services
http://www.ats.ucla.edu/stat/

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] help with function system and MS-DOS command TYPE

2007-01-30 Thread Chen, Xiao
Greetings -

I have a quick question that I hope someone will have a quick answer. I
have tried to use the R function system with the MS-DOS command type
to display the full content of a text file. But it always returns with a
message saying the text file is not found. I could accomplish the same
task with the cat command which is one of the unix-like commands that
I have installed on my windows machine. But I would like to know how it
would work with the type command.  

Here is what I have tried:

 zz-file(d:/work/test/test.txt, w)
 cat(this is a test\n, file=zz)
 close(zz)
 system(cat test.txt, show.output.on.console=T)
this is a test
 system(type test.txt, show.output.on.console=T)
test.txt not found



Thanks much for any help that you could offer. 

Best, 

Xiao Chen
Statistical Consulting Group
UCLA Academic Technology Services
http://www.ats.ucla.edu/stat/

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] help with function

2006-09-20 Thread Guenther, Cameron
Hello everyone,

I have a function here that I wrote but doesn't seem to work quite
right.  Attached is the code.  In the calib funcion under the for loop
Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1] returns NA's for everything
after years 1983 and 1984.  However the code works when it reads
Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i].  I don't quite understand why
since it should be calculating all of the necessary inputs prior to
calculating Bt[i+2].  Any help would be greatly appreciated.

Thanks

#Model parameters
B0-7500
m-0.3
R0-B0*m
z-0.8
a-B0/R0*(1-(z-0.2)/(0.8*z))
b-(z-0.2)/(0.8*z*R0)
dat-data.frame(years=seq(1983,2004),cobs=c(19032324,19032324,17531618,2
0533029,20298099,20793744,23519369,23131780,19922247,17274513,17034419,1
2448318,4551585,4226451,7183688,7407924,7538366,7336039,8869193,7902341,
6369089,6211886))
stdr-runif(100,0,0.5)
stdc-runif(100,0,0.5)
BC-runif(1000,0,100)


#model calibration

calib-function(x){
 v-sample(stdr,1)
 cr-sample(stdc,1)
 N-rnorm(1)
 Bq-sample(BC,1)
 Rerr-exp(N*v-(v^2/2))
 Cerr-exp(N*cr-(cr^2/2))
 Bt-vector();Bt[1]=B0;Bt[2]=B0
 Rt-vector()
 Ct-vector()
 for (i in 1:length(x$years)){
  Ct[i]-1/Bq*Bt[i]*Cerr
  Rt[i]-Bt[i]/(a+b*Bt[i])
  Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1]
 }
  out-new.env()
  out$yr-x$years[1:length(x$years)]
  out$Bt-Bt[1:length(x$years)]
  out$Rt-Rt[1:length(x$years)]
  out$Ct-Ct[1:length(x$years)]
  out$stdr-v
  out$stdc-cr
  out$Bq-Bq
  out$Rerr-Rerr
  out$Cerr-Cerr
  return(as.list(out))
 }
 test-calib(dat)


Cameron Guenther, Ph.D. 
Associate Research Scientist
FWC/FWRI, Marine Fisheries Research
100 8th Avenue S.E.
St. Petersburg, FL 33701
(727)896-8626 Ext. 4305
[EMAIL PROTECTED]

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with function

2006-09-20 Thread Mike Nielsen
Take the case of i==1.

Ct[i]-1/Bq*Bt[i]*Cerr  # Assign Ct[1]
using Bt[1]
  Rt[i]-Bt[i]/(a+b*Bt[i])   # Assign
Rt[1] using Bt[1]
  Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]   *Rerr-Ct[i+1]  # Assign Bt[3] using
Bt[2] and Rt[1] and **Ct[2]**


You're reading Ct[i+1] before you ever assign it, hence NA.

OSISTM

Hope this helps,

Regards,

Mike



On 9/20/06, Guenther, Cameron [EMAIL PROTECTED] wrote:
 Hello everyone,

 I have a function here that I wrote but doesn't seem to work quite
 right.  Attached is the code.  In the calib funcion under the for loop
 Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1] returns NA's for everything
 after years 1983 and 1984.  However the code works when it reads
 Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i].  I don't quite understand why
 since it should be calculating all of the necessary inputs prior to
 calculating Bt[i+2].  Any help would be greatly appreciated.

 Thanks

 #Model parameters
 B0-7500
 m-0.3
 R0-B0*m
 z-0.8
 a-B0/R0*(1-(z-0.2)/(0.8*z))
 b-(z-0.2)/(0.8*z*R0)
 dat-data.frame(years=seq(1983,2004),cobs=c(19032324,19032324,17531618,2
 0533029,20298099,20793744,23519369,23131780,19922247,17274513,17034419,1
 2448318,4551585,4226451,7183688,7407924,7538366,7336039,8869193,7902341,
 6369089,6211886))
 stdr-runif(100,0,0.5)
 stdc-runif(100,0,0.5)
 BC-runif(1000,0,100)


 #model calibration

 calib-function(x){
  v-sample(stdr,1)
  cr-sample(stdc,1)
  N-rnorm(1)
  Bq-sample(BC,1)
  Rerr-exp(N*v-(v^2/2))
  Cerr-exp(N*cr-(cr^2/2))
  Bt-vector();Bt[1]=B0;Bt[2]=B0
  Rt-vector()
  Ct-vector()
  for (i in 1:length(x$years)){
   Ct[i]-1/Bq*Bt[i]*Cerr
   Rt[i]-Bt[i]/(a+b*Bt[i])
   Bt[i+2]-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1]
  }
   out-new.env()
   out$yr-x$years[1:length(x$years)]
   out$Bt-Bt[1:length(x$years)]
   out$Rt-Rt[1:length(x$years)]
   out$Ct-Ct[1:length(x$years)]
   out$stdr-v
   out$stdc-cr
   out$Bq-Bq
   out$Rerr-Rerr
   out$Cerr-Cerr
   return(as.list(out))
  }
  test-calib(dat)


 Cameron Guenther, Ph.D.
 Associate Research Scientist
 FWC/FWRI, Marine Fisheries Research
 100 8th Avenue S.E.
 St. Petersburg, FL 33701
 (727)896-8626 Ext. 4305
 [EMAIL PROTECTED]

 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.




-- 
Regards,

Mike Nielsen

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] Help on function adf.test

2006-08-28 Thread Spiros Mesomeris
Hello everybody,
   
  I've got a matrix called EUROPEDATA and I want to calculate the adf test 
statistic (part of the tseries package) on a rolling basis for window my.win on 
each column; i.e. each column of EUROPEDATA represents a particular variable; 
for the first column I calculate the adf test statistic for window my.win = 60 
for example, roll forward one observation, calculate the adf again, and so on, 
until the end of the first column is reached and then I jump to the second 
column etc. The code for doing this is given below:
   
  adfroll - sapply(1:(ncol(EUROPEDATA)), function(i, my.data, my.win)
  {
  sss - sapply(1:(nrow(my.data)-my.win), function (j, my.data, my.win)
  { my.data - as.matrix(my.data)
  ans - adf.test(na.omit(my.data[j:(j+my.win)]))
  return(ans$p.value)
  },my.data=my.data[,i],my.win=my.win) 
  },my.data=EUROPEDATA,my.win=60,simplify=T)
   
  The problem is that the adf test does not calculate this way. There is an 
error saying:
   
  Error in embed(y, k) : wrong embedding dimension
   
  This error is generated from within the adf.test function. The embed function 
is part of the stats package, which I load before doing the adf.test.
   
  I would be very obliged if anybody were to explain to me why this happens and 
how I can correct it/ estimate what I want in a different way that will not 
invoke this error. 
   
  P.S. the function works fine if the adf.test on each column of the dataset is 
calculated, that is, without the rolling window for each column:
   
   
  summaryadf - sapply(1:ncol(EUROPEDATA),function(i,my.data)
  {
  tt - adf.test(na.omit(my.data[,i]))
  return(tt$p.value)
  },my.data=EUROPEDATA) 
   
  Please note that the same error is generated with the pp.test function of the 
tseries package
   
  Thanks in advance,
  Spyros


-

[[alternative HTML version deleted]]

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help on function adf.test

2006-08-28 Thread Gabor Grothendieck
Put your time series into a ts or zoo object.  Now using
EuStockMarkets which is builtin data set in R.  (You might
want to use align = right in rollapply.)

library(tseries)
library(zoo)
eu91 - window(EuStockMarkets, end = 1992)  # use portion for test data
eu91.p.value - rollapply(eu91, 61, function(x) adf.test(x)$p.value)

On 8/28/06, Spiros Mesomeris [EMAIL PROTECTED] wrote:
 Hello everybody,

  I've got a matrix called EUROPEDATA and I want to calculate the adf test 
 statistic (part of the tseries package) on a rolling basis for window my.win 
 on each column; i.e. each column of EUROPEDATA represents a particular 
 variable; for the first column I calculate the adf test statistic for window 
 my.win = 60 for example, roll forward one observation, calculate the adf 
 again, and so on, until the end of the first column is reached and then I 
 jump to the second column etc. The code for doing this is given below:

  adfroll - sapply(1:(ncol(EUROPEDATA)), function(i, my.data, my.win)
  {
  sss - sapply(1:(nrow(my.data)-my.win), function (j, my.data, my.win)
  { my.data - as.matrix(my.data)
  ans - adf.test(na.omit(my.data[j:(j+my.win)]))
  return(ans$p.value)
  },my.data=my.data[,i],my.win=my.win)
  },my.data=EUROPEDATA,my.win=60,simplify=T)

  The problem is that the adf test does not calculate this way. There is an 
 error saying:

  Error in embed(y, k) : wrong embedding dimension

  This error is generated from within the adf.test function. The embed 
 function is part of the stats package, which I load before doing the adf.test.

  I would be very obliged if anybody were to explain to me why this happens 
 and how I can correct it/ estimate what I want in a different way that will 
 not invoke this error.

  P.S. the function works fine if the adf.test on each column of the dataset 
 is calculated, that is, without the rolling window for each column:


  summaryadf - sapply(1:ncol(EUROPEDATA),function(i,my.data)
  {
  tt - adf.test(na.omit(my.data[,i]))
  return(tt$p.value)
  },my.data=EUROPEDATA)

  Please note that the same error is generated with the pp.test function of 
 the tseries package

  Thanks in advance,
  Spyros


 -

[[alternative HTML version deleted]]

 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] Help In Function

2006-05-12 Thread SUMANTA BASAK
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@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


Re: [R] Help In Function

2006-05-12 Thread Prof Brian Ripley
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,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-help@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


Re: [R] Help In Function

2006-05-12 Thread Simon Blomberg
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@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

__
R-help@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