[R] overwritten plots in pdf file

2009-09-29 Thread CJ Rubio

i am having a problem in saving plots in pdf. i have this code below and it
only shows me the last plot. i tried keeping my devices open by removing
dev.off() from the code but the pdf file won't open

for (i in 1:n) {
.
.
.
pdf("D:/research/plot.pdf")
plot(mon, mu, type ='o')
dev.off()
}

my for loop generates 22 plots (to be saved in pdf).. what i want is to save
all these 22 plots in just one pdf file, like 3 plots per page.

can anybody help me?

thanks in advance!

cheers,
CJ
-- 
View this message in context: 
http://www.nabble.com/overwritten-plots-in-pdf-file-tp25664260p25664260.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
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] neural network arguments

2009-10-07 Thread CJ Rubio

hi everyone!

my inquiry with neural network is rather basic. i am just learning neural
network, particularly the VR bundle. i read the documentations for the said
bundle but still is struggling on understanding some arguments

- x is the matrix or data frame of x values for example
   does this mean data frame for training?

- y is the matrix or data frame of target values for example
   does this mean data frame for testing?

- would fitting the single-hidden-layer NN train and test my data? what does
"fitting" really do?


i know these are very basic questions but i just started exploring NN
packages.
thanks in advance for your help!
-- 
View this message in context: 
http://www.nabble.com/neural-network-arguments-tp25787734p25787734.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] acf for a univariate time series in a data frame

2009-10-08 Thread CJ Rubio

hi everyone!

i want to check the autocorrelation function for a univariate time series
(streamflow) in a data frame as below:

< DF <- read.table("D:/file path")
< DF

year  jan  feb  mar  apr ..   dec
1966   0.504   0.406   0.740   0.241   0.429
1967   0.683   0.529   0.780   0.443   0.503
.
.
.
.

what i first tried is:
acf (DF, plot = TRUE)

the resulting plot is correlation between each month ( jan, jan and feb, feb
and march).

what i need is a correlation that would help me find out which lag would be
the most significant. i know i am missing out something simple here. please
bear with me.

should i transform my data frame into a vector of series:

< DF

01/1966   0.504
02/1966   0.406
03/1966   0.740



before i do the command
acf(DF, plot = TRUE)???
thanks in advance!
-- 
View this message in context: 
http://www.nabble.com/acf-for-a-univariate-time-series-in-a-data-frame-tp25799751p25799751.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] acf for a univariate time series in a data frame

2009-10-08 Thread CJ Rubio

*additional:
the lags i am expecting is in months.. since i am trying to predict monthly
streamflow.

thanks again
-- 
View this message in context: 
http://www.nabble.com/acf-for-a-univariate-time-series-in-a-data-frame-tp25799751p25799784.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] simulating AR() using a

2009-10-21 Thread CJ Rubio

good day everyone!

i have a time series (andong.ts) and fitted and AR() model using the
following code

andong.ts <- ts(read.table("D:/.../andong.csv", header = TRUE), start =
c(1966,1), frequency = 1)

ar(andong.ts)

Call:
ar(x = andong)

Coefficients:
 1   2   3  
0.3117  0.0607  0.0999  

Order selected 3  sigma^2 estimated as  0.8443 


I am aware that my model is now 

 x(t) = 0.3117x(t-1) + 0.0607x(t-2) + 0.0999x(t-3) + e(t)   
eqn(1)



but i am not sure of how to perform my simulation for the new series. i
tried to look at arima.sim, 

arima.sim(ar = c(0.3117,0.0607, 0.0999), n = 36)



but it doesn't seem to use the old series that should be simulated (or maybe
it is but i am not aware)

Could anyone please brief me on how to perform my simulation properly which
would perform eqn (1) with e(t) being the residual series? 

thanks in advance!!!

-- 
View this message in context: 
http://www.nabble.com/simulating-AR%28%29-using-a-tp26002850p26002850.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
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 in simulating AR models

2009-10-21 Thread CJ Rubio

good day everyone!

i have a time series (andong.ts) and fitted and AR() model using the
following code 

andong.ts <- ts(read.table("D:/.../andong.csv", header = TRUE), start =
c(1966,1), frequency = 1) 

ar(andong.ts) 

Call: ar(x = andong)

Coefficients:
1 2   3
 0.3117  0.06070.0999 

Order selected 3 sigma^2 estimated as 0.8443



 I am aware that my model is now

 x(t) = 0.3117x(t-1) + 0.0607x(t-2) + 0.0999x(t-3) + e(t)   
  
eqn(1)




but i am not sure of how to perform my simulation for the new series. i
tried to look at arima.sim, 
arima.sim(ar = c(0.3117,0.0607, 0.0999), n = 36) 


but it doesn't seem to use the old series that should be simulated (or maybe
it is but i am not aware) Could anyone please brief me on how to perform my
simulation properly which would perform eqn (1) with e(t) being the residual
series?


 thanks in advance!!!

-- 
View this message in context: 
http://www.nabble.com/help-in-simulating-AR-models-tp26003111p26003111.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] how to create normal qqplot with the 95% confidence interval

2009-12-23 Thread CJ Rubio

hi everyone!

season's greetings!

is there any way that i can create a normal qqplot showing, aside from the
qqline, the 95% confidence limits? thank you very much..

happy holidays!
-- 
View this message in context: 
http://n4.nabble.com/how-to-create-normal-qqplot-with-the-95-confidence-interval-tp977727p977727.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] how to create normal qqplot with the 95% confidence interval

2009-12-23 Thread CJ Rubio

thank you very much! this is just what my professor was asking for.



Walmes Zeviani wrote:
> 
> Rubio,
> 
> 
> Look at library(fBasics) the function qqnormPlot(). Below an example:
> 
> qqnormPlot(rnorm(100))
> 
> Best's
> 
> Walmes Zeviani, Brasil.
> 
> 
> 
> 
> 
> CJ Rubio wrote:
>> 
>> hi everyone!
>> 
>> season's greetings!
>> 
>> is there any way that i can create a normal qqplot showing, aside from
>> the qqline, the 95% confidence limits? thank you very much..
>> 
>> happy holidays!
>> 
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/how-to-create-normal-qqplot-with-the-95-confidence-interval-tp977727p978298.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 in identifying the argument "formula" in the package nnet

2010-01-28 Thread CJ Rubio

hi everyone!

I have a 40-year monthy streamflow record. And i want to fit a neural
network. I already fitted an autoregressive model and found out that an
AR(3) model fits my time series (time.series) the best. 

I am currently having problems on how to express the argument "formula" for
my neural network.. I am aware that my model should be Q(t) ~ Q(t-1) +
Q(t-2) + Q(t-3). But I can't seem to figure out how to express this in a
formula that R would recognize.

Any help, suggestions and comments to enlighten me will be truly
appreciated.

CJ Rubio

-- 
View this message in context: 
http://n4.nabble.com/help-in-identifying-the-argument-formula-in-the-package-nnet-tp1401467p1401467.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] how to express time series linear model Q(t) ~ Q(t-1)+.. Q(t-n) as a formula

2010-01-28 Thread CJ Rubio

For example I have a time series

Q(t) ~ Q(t-1) + Q(t-2) + Q(t-3)

meaning that my current value is dependent to the 3 previous values.

Can anybody help me express this in a formula that I can use for my neural
network model (I am planning to use packages "nnet" and "MASS")
-- 
View this message in context: 
http://n4.nabble.com/how-to-express-time-series-linear-model-Q-t-Q-t-1-Q-t-n-as-a-formula-tp1401479p1401479.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] annual maximum value

2009-02-16 Thread CJ Rubio

 hi everyone!

hope you can help me here.

i am a new R user. what i am trying to do is to find the maximum annual
discharge from a daily record. i have a data.frame which includes date and
the discharge. somewhat like this..

10/1/1989   2410
10/2/1989   2460
10/3/1989   2890
...
...
...
12/31/2005 5730

i have been browsing through the archives and fount out about the aggregate
function and the zoo package. here's one of the codes i've tried

DF <- read.table(data[i], sep =",")  ##i have several stations to assimilate
Date <- as.Date(as.character(DF[,3]), "%m/%d/%Y") #the date is at the 3rd
column, obviously
library(zoo)
z <- aggregate(zoo(DF[,4]), cut(Date, "y"), max)
max.discharge <- coredata(z)
date <- time(z)

the result should somehow look like this 
11/21/1926  32600
 4/24/1927   66500
...
...
..
4/26/2005   111000

thanks for your time reading my questions,, any suggestions will be truly
appreciated...
  


-- 
View this message in context: 
http://www.nabble.com/annual-maximum-value-tp22049205p22049205.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
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] annual maximum value

2009-02-16 Thread CJ Rubio

thank you very much for your reply.

i studied the code you gave me and tried to make adjustments to fit the
requirements that i need, thank you again.. i used the following codes:

> m <- read.table("D:/documents/5 stations/01014000.csv", sep =",")
> z <- zoo(m[,4],as.Date(as.character(DF[,3]), "%m/%d/%Y"))
> x <- aggregate(z, cut(time(z),"y"), max)

i got the maximum values right using coredata(), my question now is, how can
i call for the complete date (-mm-dd)  and the year () when the
maximum observation for that year was observed? 




CJ Rubio wrote:
> 
>  hi everyone!
> 
> hope you can help me here.
> 
> i am a new R user. what i am trying to do is to find the maximum annual
> discharge from a daily record. i have a data.frame which includes date and
> the discharge. somewhat like this..
> 
> 10/1/1989   2410
> 10/2/1989   2460
> 10/3/1989   2890
> ...
> ...
> ...
> 12/31/2005 5730
> 
> i have been browsing through the archives and fount out about the
> aggregate function and the zoo package. here's one of the codes i've tried
> 
> DF <- read.table(data[i], sep =",")  ##i have several stations to
> assimilate
> Date <- as.Date(as.character(DF[,3]), "%m/%d/%Y") #the date is at the 3rd
> column, obviously
> library(zoo)
> z <- aggregate(zoo(DF[,4]), cut(Date, "y"), max)
> max.discharge <- coredata(z)
> date <- time(z)
> 
> the result should somehow look like this 
> 11/21/1926  32600
>  4/24/1927   66500
> ...
> ...
> ..
> 4/26/2005   111000
> 
> thanks for your time reading my questions,, any suggestions will be truly
> appreciated...
>   
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/annual-maximum-value-tp22049205p22051398.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 dates in zoo package

2009-02-17 Thread CJ Rubio

i have the following code - assimilating the maximum annual discharge each
year ffrom a daily discharge record from year 1989-2005.

m <- read.table("D:/documents/5 stations/01014000.csv", sep =",")
z <- zoo(m[,4],as.Date(as.character(m[,3]), "%m/%d/%Y")) 
x <- aggregate(z, floor(as.numeric(as.yearmon(time(z, max)   #code
suggested by Gabor Grothendieck

which gives me the maximum discharge each year and the year itself.. what i
am trying now is to produce the date when the maximum discharge was observed
in the pattern -mm-dd, like:

1988 11/9/1988  18600
1989  5/8/1989   49000
...
2005 4/26/2005111000 

thank you all in advance...
-- 
View this message in context: 
http://www.nabble.com/problem-with-dates-in-zoo-package-tp22053103p22053103.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] rbind: number of columns of result is not a multiple of vector length (arg 1)

2009-02-17 Thread CJ Rubio

i have the following constructed and running very well,, thanks to Gabor
Grothendieck for his help.

>data.info <- c("station.id", "year", "date", "max.discharge")
>
> for(i in 1:num.files) {
+ station.id <- substring(data[i], 1,8)
+ DF <- read.table(data[i], sep=",", blank.lines.skip = TRUE)
+ z <- zoo(DF[,4], as.Date(as.character(DF[,3]), "%m/%d/%Y"))
+ f <- function(x) time(x) [which.max(x)]
+ ix <- tapply(z, floor(as.yearmon(time(z))),f)
+ year <- (1988:2005)
+ date <- time(z[ix])
+ max.discharge <- coredata(z[ix])
+ data.info <- rbind(data.info, c(station.id, year, date, max.discharge))
+ }

my problem with my code occurs in the part where I arrange my results..
after running this code, i get this warning:

Warning message:
In rbind(data.info, c(station.id, year, date, max.discharge)) :
  number of columns of result is not a multiple of vector length (arg 1)


i can't figure out what to do to produce the result i wanted:
(for each station, it should look like this:)

data.info "station.id" "year"   "date"  "max.discharge" 
   "01014000" 1988   "1988-11-07"   4360 
   "01014000" 1989   "1989-05-13" 2  
   "01014000" 1990   "1990-10-25"   9170
   "01014000" 1991   "1991-04-22" 12200
   "01014000" 1992   "1992-03-29" 11800

   "01014000" 2005   "2005-04-04" 22100

thanks in advence for your help..
-- 
View this message in context: 
http://www.nabble.com/rbind%3A-number-of-columns-of-result-is-not-a-multiple-of-vector-length-%28arg-1%29-tp22070942p22070942.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] rbind: number of columns of result is not a multiple of vector length (arg 1)

2009-02-17 Thread CJ Rubio

it works perfectly thank you for your help

what if i want to seperate each stations data and save in a .csv file??
while i'm asking you these i'm also finding some ways to do so..

thank you again.





jholtman wrote:
> 
> try using:
> 
> data.info <- rbind(data.info, cbind(station.id, year, date,
> max.discharge))
> 
> On Tue, Feb 17, 2009 at 9:26 PM, CJ Rubio  wrote:
>>
>> i have the following constructed and running very well,, thanks to Gabor
>> Grothendieck for his help.
>>
>>>data.info <- c("station.id", "year", "date", "max.discharge")
>>>
>>> for(i in 1:num.files) {
>> + station.id <- substring(data[i], 1,8)
>> + DF <- read.table(data[i], sep=",", blank.lines.skip = TRUE)
>> + z <- zoo(DF[,4], as.Date(as.character(DF[,3]), "%m/%d/%Y"))
>> + f <- function(x) time(x) [which.max(x)]
>> + ix <- tapply(z, floor(as.yearmon(time(z))),f)
>> + year <- (1988:2005)
>> + date <- time(z[ix])
>> + max.discharge <- coredata(z[ix])
>> + data.info <- rbind(data.info, c(station.id, year, date, max.discharge))
>> + }
>>
>> my problem with my code occurs in the part where I arrange my results..
>> after running this code, i get this warning:
>>
>> Warning message:
>> In rbind(data.info, c(station.id, year, date, max.discharge)) :
>>  number of columns of result is not a multiple of vector length (arg 1)
>>
>>
>> i can't figure out what to do to produce the result i wanted:
>> (for each station, it should look like this:)
>>
>> data.info "station.id" "year"   "date"  "max.discharge"
>>   "01014000" 1988   "1988-11-07"   4360
>>   "01014000" 1989   "1989-05-13" 2
>>   "01014000" 1990   "1990-10-25"   9170
>>   "01014000" 1991   "1991-04-22" 12200
>>   "01014000" 1992   "1992-03-29" 11800
>>
>>   "01014000" 2005   "2005-04-04" 22100
>>
>> thanks in advence for your help..
>> --
>> View this message in context:
>> http://www.nabble.com/rbind%3A-number-of-columns-of-result-is-not-a-multiple-of-vector-length-%28arg-1%29-tp22070942p22070942.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.
>>
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 
> __
> 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://www.nabble.com/rbind%3A-number-of-columns-of-result-is-not-a-multiple-of-vector-length-%28arg-1%29-tp22070942p22071324.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] basic inquiry regarding write.csv

2009-02-17 Thread CJ Rubio

i have a loop which looks likes this:


> data.info <- rbind(data.info, cbind(station.id, year, date,
> max.discharge))
+  y <- split(data.info, data.info[station.id])
+  for (i in names(y))
 {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}

i am wondering, where the file (which i am about to write in .csv format)
will be saved? i looked at ?write.csv and it says there that :

file   either a character string naming a file or a
connection open for writing. "" indicates output to the console. 

correct me if i'm wrong but the way i undestand it is, i should have a file
or a working directory where the .csv will be written.  if for example i
have a working directory "E:/my_work_directory", how can i save this
splitted files in the same directory?

can anybody please enlighten me more with write.csv and the argument file?

thanks..

-- 
View this message in context: 
http://www.nabble.com/basic-inquiry-regarding-write.csv-tp22073053p22073053.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] basic inquiry regarding write.csv

2009-02-17 Thread CJ Rubio

thanks for your reply.. is there something wrong with the code i have?
because it doesn't write the file in the directory that i am using...

for (i in names(y))
> {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}

thanks again..



ronggui-2 wrote:
> 
> If the "file" is a relative path, then it should be in the working
> directory. Say, the working directory is E:/my_work_directory (of
> course, you can get it by getwd()), and you export a data frame "a" to
> csv by:
> write.csv(a, file="a.csv"), then the file should be
> "E:/my_work_directory/a.csv".
> 
> Best
> 
> 2009/2/18 CJ Rubio :
>>
>> i have a loop which looks likes this:
>>
>>
>>> data.info <- rbind(data.info, cbind(station.id, year, date,
>>> max.discharge))
>> +  y <- split(data.info, data.info[station.id])
>> +  for (i in names(y))
>> {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}
>>
>> i am wondering, where the file (which i am about to write in .csv format)
>> will be saved? i looked at ?write.csv and it says there that :
>>
>> file   either a character string naming a file or a
>> connection open for writing. "" indicates output to the console.
>>
>> correct me if i'm wrong but the way i undestand it is, i should have a
>> file
>> or a working directory where the .csv will be written.  if for example i
>> have a working directory "E:/my_work_directory", how can i save this
>> splitted files in the same directory?
>>
>> can anybody please enlighten me more with write.csv and the argument
>> file?
>>
>> thanks..
>>
>> --
>> View this message in context:
>> http://www.nabble.com/basic-inquiry-regarding-write.csv-tp22073053p22073053.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.
>>
> 
> 
> 
> -- 
> HUANG Ronggui, Wincent
> Tel: (00852) 3442 3832
> PhD Candidate
> Dept of Public and Social Administration
> City University of Hong Kong
> Homepage: http://ronggui.huang.googlepages.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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/basic-inquiry-regarding-write.csv-tp22073053p22073393.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] basic inquiry regarding write.csv

2009-02-17 Thread CJ Rubio

this is the code that i have so far:

> data.path <- file.path ("D:/documents/research/5 stations")
> setwd(data.path)
> getwd()

> data <- dir(".")
> num.files <- length(data)

>  for(i in 1:num.files) {
+  station.id <- substring(data[i], 1,8)
+  DF <- read.table(data[i], sep=",", blank.lines.skip = TRUE)
+  z <- zoo(DF[,4], as.Date(as.character(DF[,3]), "%m/%d/%Y"))
+  f <- function(x) time(x) [which.max(x)]
+  ix <- tapply(z, floor(as.yearmon(time(z))),f)
+  year <- (1988:2005)
+  date <- time(z[ix])
+  max.discharge <- coredata(z[ix])
+  data.info <- rbind(data.info, cbind(station.id, year, date,
max.discharge))
+  y <- split(data.info, data.info[station.id])
+  for (i in names(y)) {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}
+ }

i have done the suggestion you gave me..  and there were no errors when i
run it.
hope this would further clarify my question.



So far, I cannot see any mistake, though the sep="" will be more
elegant that sep=",". Are you sure your working directory is
"E:/my_work_directory"? and is there any error msg?

BTW, a reproducible example will help to get better response from the list.

2009/2/18 CJ Rubio :
>
> thanks for your reply.. is there something wrong with the code i have?
> because it doesn't write the file in the directory that i am using...
>
> for (i in names(y))
>> {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}
>
> thanks again..
>
>
>
> ronggui-2 wrote:
>>
>> If the "file" is a relative path, then it should be in the working
>> directory. Say, the working directory is E:/my_work_directory (of
>> course, you can get it by getwd()), and you export a data frame "a" to
>> csv by:
>> write.csv(a, file="a.csv"), then the file should be
>> "E:/my_work_directory/a.csv".
>>
>> Best
>>
>> 2009/2/18 CJ Rubio :
>>>
>>> i have a loop which looks likes this:
>>>
>>>
>>>> data.info <- rbind(data.info, cbind(station.id, year, date,
>>>> max.discharge))
>>> +  y <- split(data.info, data.info[station.id])
>>> +  for (i in names(y))
>>> {write.csv(y[[i]], file=paste(i, ".csv", sep=","))}
>>>
>>> i am wondering, where the file (which i am about to write in .csv
>>> format)
>>> will be saved? i looked at ?write.csv and it says there that :
>>>
>>> file   either a character string naming a file or a
>>> connection open for writing. "" indicates output to the console.
>>>
>>> correct me if i'm wrong but the way i undestand it is, i should have a
>>> file
>>> or a working directory where the .csv will be written.  if for example i
>>> have a working directory "E:/my_work_directory", how can i save this
>>> splitted files in the same directory?
>>>
>>> can anybody please enlighten me more with write.csv and the argument
>>> file?
>>>
>>> thanks..
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/basic-inquiry-regarding-write.csv-tp22073053p22073053.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.
>>>
>>
>>
>>
>> --
>> HUANG Ronggui, Wincent
>> Tel: (00852) 3442 3832
>> PhD Candidate
>> Dept of Public and Social Administration
>> City University of Hong Kong
>> Homepage: http://ronggui.huang.googlepages.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.
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/basic-inquiry-regarding-write.csv-tp22073053p22073393.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://