Re: [R] library(fCalendar) timeDate("12.03.2005", format="%d.%m.%Y")

2007-08-20 Thread Martin Becker
Dear Ola,

I think you spotted a small bug in *package* fCalendar.
Explicit specification should prevent "autodetection" of the date 
format, which is not the case for fCalendar v251.70, instead 
autodetection is done at least once (twice, if actually appropriate).
With the following patch, things should work ok:

diff --recursive fCalendar.orig/R/3A-TimeDateClass.R 
fCalendar/R/3A-TimeDateClass.R
433c433
< charvec = format(strptime(charvec, .whichFormat(charvec)), isoFormat)
---
 > charvec = format(strptime(charvec, format), isoFormat)

You did not provide the output of sessionInfo() (which you are asked for 
in the posting guide). If you are using Windows and don't know how to 
apply the patch, you can download a patched binary version here:
   
   http://www.saar-gate.net/download/fCalendar_251.70.zip

Regards,

   Martin

PS: Maybe r-sig-finance is more appropriate for questions concerning 
Rmetrics.


Ola Lindqvist wrote:
> Dear R users,
> I have problem with the library fCalendar.
>
> I am not using the US standard format notations. It seems like it is not 
> possible to have different format than the US standards.
> Anyone how knows a way to go around this problem?
>
> Here is the code I enter:
> myDate = "12.03.2005"
> timeDate(myDate, format = "%d.%m.%Y")
>
> And I get following error message:
> Error in if (sum(lt$sec + lt$min + lt$hour) == 0) isoFormat = "%Y-%m-%d" :
> missing value where TRUE/FALSE needed
>
> Thanks,
> Ola
>
> __
> 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.


Re: [R] library(fCalendar) timeDate("12.03.2005", format="%d.%m.%Y")

2007-08-22 Thread Martin Becker
Martin Maechler wrote:
>>>>>> "OL" == Ola Lindqvist <[EMAIL PROTECTED]>
>>>>>> on Tue, 21 Aug 2007 14:32:19 +0200 writes:
>>>>>> 
>
> OL> Thanks!
> OL> Seems to work fine now!
>
> Well, for your example.
>
> But sorry to say, the patch breaks other cases.
>
> I'm investigating further
> (and will hopefully contribute to a new CRAN release of fCalendar
>  once Diethelm Wuertz is back from wherever; I've already made
>  more changes)
>
>   

Good to see experts investigating :-)

Sorry, I should have mentioned, at least, that I am not an Rmetrics 
developer, that I only took a quick glance at the code (focused on the 
reported problem), and that the patched version is neither official nor 
tested. Now I see that I completely messed up the case for "Date" input 
and sometimes .midnightStandard() was not working correct any more.

One further issue, which was brought to my attention by another R-user 
off list: I think, that all occurences of

  if (sum(lt$sec+lt$min+lt$hour) == 0) isoFormat = "%Y-%m-%d"

in R/3A-TimeDateClass.R could safely be replaced by

  if (sum(lt$sec+lt$min+lt$hour,na.rm=TRUE) == 0) isoFormat = "%Y-%m-%d"

in order to make fCalendar more NA-friendly. Currently, at least for 
some cases, a single NA entry in the input vector suffices to let 
timeDate() break down. Again, I am not sure, if this change breaks some 
special cases, or if breaking down in case of NAs is intended.

Nevertheless, I have built a new, unofficial and untested patched 
(windows-)version of fCalendar (same weblink), which makes the "Date" 
input case and .midnightStandard() working again (I hope so, at least), 
and incorporates  the (improved?) NA-handling. But of course: only use 
this version with care (and only if the official version doesn't work 
for your particular problem). Hopefully, we see an official update on 
CRAN soon :-)

Kind regards,

  Martin Becker


> Martin Maechler,
> ETH Zurich  [but different department than D.Wuertz]
>
>
> OL> Martin Becker wrote:
> >> Dear Ola,
> >> 
> >> I think you spotted a small bug in *package* fCalendar.
> >> Explicit specification should prevent "autodetection" of the date 
> >> format, which is not the case for fCalendar v251.70, instead 
> >> autodetection is done at least once (twice, if actually appropriate).
> >> With the following patch, things should work ok:
> >> 
> >> diff --recursive fCalendar.orig/R/3A-TimeDateClass.R 
> >> fCalendar/R/3A-TimeDateClass.R
> >> 433c433
> >> < charvec = format(strptime(charvec, .whichFormat(charvec)), 
> >> isoFormat)
> >> ---
> >> > charvec = format(strptime(charvec, format), isoFormat)
> >> 
> >> You did not provide the output of sessionInfo() (which you are asked 
> >> for in the posting guide). If you are using Windows and don't know how 
> >> to apply the patch, you can download a patched binary version here:
> >> http://www.saar-gate.net/download/fCalendar_251.70.zip
> >> 
> >> Regards,
> >> 
> >> Martin
> >> 
> >> PS: Maybe r-sig-finance is more appropriate for questions concerning 
> >> Rmetrics.
> >> 
> >> 
> >> Ola Lindqvist wrote:
> >>> Dear R users,
> >>> I have problem with the library fCalendar.
> >>> 
> >>> I am not using the US standard format notations. It seems like it is 
> >>> not possible to have different format than the US standards.
> >>> Anyone how knows a way to go around this problem?
> >>> 
> >>> Here is the code I enter:
> >>> myDate = "12.03.2005"
> >>> timeDate(myDate, format = "%d.%m.%Y")
> >>> 
> >>> And I get following error message:
> >>> Error in if (sum(lt$sec + lt$min + lt$hour) == 0) isoFormat = 
> >>> "%Y-%m-%d" :
> >>> missing value where TRUE/FALSE needed
> >>> 
> >>> Thanks,
> >>> Ola
> >>> 
> >>> __
> >>> 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.
> >>> 
> >> 
>
> OL> __
> OL> R-help@stat.math.ethz.ch mailing list
> OL> https://stat.ethz.ch/mailman/listinfo/r-help
> OL> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> OL> 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.


Re: [R] Behaviour of very large numbers

2007-08-30 Thread Martin Becker
willem vervoort wrote:
> Dear all,
> I am struggling to understand this.
>
> What happens when you raise a negative value to a power and the result
> is a very large number?
>
>  B
> [1] 47.73092
>
>   
>> -51^B
>> 
> [1] -3.190824e+81
>
> # seems fine
>   

Well, this seems not to be what you intended to do, you didn't raise a 
negative value to a power, but you got the negative of a positive number 
raised to that power (operator precedence, -51^B is the same as -(51^B) 
and not the same as (-51)^B...).

If you really want to raise a negative value to a fractional power, you 
may want to tell R to use complex numbers:

B <- 47.73092
x <- complex(real=seq(-51,-49,length=10))

x^B

 [1] 2.117003e+81-2.387323e+81i 1.718701e+81-1.938163e+81i
 [3] 1.394063e+81-1.572071e+81i 1.129702e+81-1.273954e+81i
 [5] 9.146212e+80-1.031409e+81i 7.397943e+80-8.342587e+80i
 [7] 5.978186e+80-6.741541e+80i 4.826284e+80-5.442553e+80i
 [9] 3.892581e+80-4.389625e+80i 3.136461e+80-3.536955e+80i
 >

Regards,

  Martin


> # now this:
>   
>> x <- seq(-51,-49,length=100)
>> 
>
>   
>> x^B
>> 
>   [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 
> 
>   
>> is.numeric(x^B)
>> 
> [1] TRUE
>   
>> is.real(x^B)
>> 
> [1] TRUE
>   
>> is.infinite(x^B)
>> 
>   [1] FALSE FALSE FALSE FALSE FALSE
>
> I am lost, I checked the R mailing help, but could not find anything
> directly. I loaded package Brobdingnag and tried:
> as.brob(x^B)
>   [1] NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN)
>   
>> as.brob(x)^B
>> 
>   [1] NAexp(187.67) NAexp(187.65) NAexp(187.63) NAexp(187.61)
>
> I guess I must be misunderstanding something fundamental.
>
> Any clues would be really appreciated.
> Willem
>
> __
> 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.


Re: [R] FW: variable format

2007-09-07 Thread Martin Becker
Dear Cory,

I am not familiar with SAS, but is this what you are looking for?

divisionTable <- matrix(c(1, "New England",
  2, "Middle Atlantic",
  3, "East North Central",
  4, "West North Central",
  5, "South Atlantic",
  6, "East South Central",
  7, "West South Central",
  8, "Mountain",
  9, "Pacific"),
ncol=2, byrow=T)
a <- NULL
a$divisionOld <- c(0,1,2,3,4,5)
a$divisionNew <- 
as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2]))
a$divisionNew

[1] NA   "New England""Middle Atlantic"  
[4] "East North Central" "West North Central" "South Atlantic" 


Kind regards,

  Martin


Cory Nissen schrieb:
>
>
> Anybody?  
>
>
> 
>
> From: Cory Nissen
> Sent: Tue 9/4/2007 9:30 AM
> To: r-help@stat.math.ethz.ch
> Subject: variable format
>
>
> Okay, I want to do something similar to SAS proc format.
>
> I usually do this...
>
> a <- NULL
> a$divisionOld <- c(1,2,3,4,5)
> divisionTable <- matrix(c(1, "New England",
>   2, "Middle Atlantic",
>   3, "East North Central",
>   4, "West North Central",
>   5, "South Atlantic"),
> ncol=2, byrow=T)
> a$divisionNew[match(a$divisionOld, divisionTable[,1])] <- divisionTable[,2]
>
> But how do I handle the case where...
> a$divisionOld <- c(0,1,2,3,4,5)   #no format available for 0, this throws an 
> error.
> OR
> divisionTable <- matrix(c(1, "New England",
>   2, "Middle Atlantic",
>   3, "East North Central",
>   4, "West North Central",
>   5, "South Atlantic",
>   6, "East South Central",
>   7, "West South Central",
>   8, "Mountain",
>   9, "Pacific"),
> ncol=2, byrow=T)   
> There are extra formats available... this throws a warning.
>
> Thanks
>
> Cory
>
>   [[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.


Re: [R] FW: variable format

2007-09-08 Thread Martin Becker
Frank E Harrell Jr wrote:
> Martin Becker wrote:
>> Dear Cory,
>>
>> I am not familiar with SAS, but is this what you are looking for?
>>
>> divisionTable <- matrix(c(1, "New England",
>>   2, "Middle Atlantic",
>>   3, "East North Central",
>>   4, "West North Central",
>>   5, "South Atlantic",
>>   6, "East South Central",
>>   7, "West South Central",
>>   8, "Mountain",
>>   9, "Pacific"),
>> ncol=2, byrow=T)
>
> How about just divisionTable <- c('New England', 'Middle Atlantic', 
> ...) then factor(old, 1:9, divisionTable) ?
>
> Frank
>

Of course, this solution is more elegant, but my intention was
1. to provide a solution which makes use of the exisiting object 
"divisionTable"
2. to reproduce the output from the working example (->conversion to 
character)
Maybe I should have emphasized that I was quoting the existing 
definition of divisionTable from the original email (for the sake of 
providing self-contained code) and not introducing a unnecessarily 
complicated new definition of divisionTable.

Regards,

 Martin

>> a <- NULL
>> a$divisionOld <- c(0,1,2,3,4,5)
>> a$divisionNew <- 
>> as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2]))
>>  
>>
>> a$divisionNew
>>
>> [1] NA   "New England""Middle Atlantic"  [4] 
>> "East North Central" "West North Central" "South Atlantic"
>>
>> Kind regards,
>>
>>   Martin
>>
>>
>> Cory Nissen schrieb:
>>> 
>>> Anybody? 
>>>
>>> 
>>>
>>> From: Cory Nissen
>>> Sent: Tue 9/4/2007 9:30 AM
>>> To: r-help@stat.math.ethz.ch
>>> Subject: variable format
>>>
>>>
>>> Okay, I want to do something similar to SAS proc format.
>>>
>>> I usually do this...
>>>
>>> a <- NULL
>>> a$divisionOld <- c(1,2,3,4,5)
>>> divisionTable <- matrix(c(1, "New England",
>>>   2, "Middle Atlantic",
>>>   3, "East North Central",
>>>   4, "West North Central",
>>>   5, "South Atlantic"),
>>> ncol=2, byrow=T)
>>> a$divisionNew[match(a$divisionOld, divisionTable[,1])] <- 
>>> divisionTable[,2]
>>>
>>> But how do I handle the case where...
>>> a$divisionOld <- c(0,1,2,3,4,5)   #no format available for 0, this 
>>> throws an error.
>>> OR
>>> divisionTable <- matrix(c(1, "New England",
>>>   2, "Middle Atlantic",
>>>   3, "East North Central",
>>>   4, "West North Central",
>>>   5, "South Atlantic",
>>>   6, "East South Central",
>>>   7, "West South Central",
>>>   8, "Mountain",
>>>   9, "Pacific"),
>>> ncol=2, byrow=T)   There are extra formats 
>>> available... this throws a warning.
>>>
>>> Thanks
>>>
>>> Cory
>>>
>>> [[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@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] count sequence of integers

2007-02-15 Thread Martin Becker
Samuel Kemp wrote:
> Hi,
>
> I would like to be able to count a sequence of numbers. For example, given a
> vector of the following integers
>
> (1,1,1,2,2,2,2,3,3,3,3,3,3,1,1,1,1, 3,3)
>
> the function would return
>
> (3, 4, 6, 4,2)
>
> Does anyone have any cool ideas to solve this?
>
>   
Maybe not the most efficient way, but

 >  count <- function (x) diff(c(0,which(diff(x)!=0),length(x)))

should work (for integer sequences!):

 >  x<-c(1,1,1,2,2,2,2,3,3,3,3,3,3,1,1,1,1,3,3)
 >  count(x)
[1] 3 4 6 4 2

Regards,

  Martin

> Any help appreciated.
>
> Regards,
>
> Sam.
>
>   [[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.


Re: [R] GarchOxFit Interface

2007-03-03 Thread Martin Becker
[EMAIL PROTECTED] wrote:
> Hello,
>
> I am having problems with the GarchOxFit. I have my Ox Console instaled in
> c:\Program Files\ox, and when I execute the GarchOxFit the result is 
> C:\Ox\bin\oxl.exe not found. I there any posiblility to execute the command
> without installing again Ox in c:\?
>
>   
I suppose you are speaking of GarchOxFit in package fSeries, but you 
didn't mention which version of fSeries you are using. I think, in 
current versions (240.10068), you may set OXPATH in the global 
environment to your installation of OX, maybe it is even necessary to do so.
Apart from that I think there is still a buglet in the Ox-Interface 
functions, which I mentioned some time ago on R-sig-finance, see  
https://stat.ethz.ch/pipermail/r-sig-finance/2005q4/000498.html. I think 
you still find this buglet in the current version source (line 217 of 
4D-GarchOxInterface.R), but since I don't use the Ox interface any more, 
I am not sure. I think the quick workaround is to always store the time 
series to be fitted in the variable "x" in the global environment.

hth,
  Martin
> My OS is windows XP.
>
> Thankyou for your help.
>
> Pilar Grau
>
> __
> 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.


Re: [R] Reading a csv file row by row

2007-04-06 Thread Martin Becker
readLines (which is mentioned in the "See also" section of ?scan with 
the hint "to read a file a line at a time") should work.

Regards,
  Martin

Yuchen Luo schrieb:
> Hi, my friends.
> When a data file is large, loading the whole file into the memory all
> together is not feasible. A feasible way  is to read one row, process it,
> store the result, and read the next row.
>
>
> In Fortran, by default, the 'read' command reads one line of a file, which
> is convenient, and when the same 'read' command is executed the next time,
> the next row of the same file will be read.
>
> I tried to replicate such row-by-row reading in R.I use scan( ) to do so
> with the "skip= xxx " option. It takes only seconds when the number of the
> rows is within 1000. However, it takes hours to read 1 rows. I think it
> is because every time R reads, it needs to start from the first row of the
> file and count xxx rows to find the row it needs to read. Therefore, it
> takes more time for R to locate the row it needs to read.
>
> Is there a solution to this problem?
>
> Your help will be highly appreciated!
>
>   [[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.


Re: [R] Error: cannot change value of locked binding for

2007-04-20 Thread Martin Becker
Did you have a look at the posting guide?
We have to guess that you are using some version of fOptions in some 
version of R under some OS, and that you run code from the examples 
section of ?MonteCarloOption relying on other code from that section 
which is not mentioned at all. Given that these guesses are correct:
The first parameter of MonteCarloOption should read "delta.t", not "dt" 
(at least in fOptions version 241.68). If you are using "dt" because you 
have an old version of fOptions and "dt" is correct for that version, 
try updating fOptions, otherwise maybe changing "dt" to "delta.t" helps.
Regards,

  Martin

[EMAIL PROTECTED] wrote:
> Hello R experts
>
> What does this error means and how to resolve this issue (cannot change 
> value of locked binding for ). Please suggest 
>
>   
>> mc = MonteCarloOption(dt = 1/360, pathLength = 30, mcSteps = 5000, 
>> 
> mcLoops =
> + 50, init = TRUE, innovations.gen = sobolInnovations, path.gen = 
> wienerPath,
> + payoff.calc = arithmeticAsianPayoff, antithetic = TRUE, standardization 
> =
> + FALSE, trace = TRUE, scrambling = 2, seed = 4711)
> Error in MonteCarloOption(dt = 1/360, pathLength = 30, mcSteps = 5000,  : 
> cannot change value of locked binding for 'dt'
>   
>
>
> Thanks in advance
>
>Sayonara With Smile & With Warm Regards :-)
>
>   G a u r a v   Y a d a v
>   Assistant Manager,
>   Economic Research & Surveillance Department,
>   Clearing Corporation Of India Limited.
>
>   Address: 5th, 6th, 7th Floor, Trade Wing 'C',  Kamala City, S.B. Marg, 
> Mumbai - 400 013
>   Telephone(Office): - +91 022 6663 9398 ,  Mobile(Personal) (0)9821286118
>   Email(Office) :- [EMAIL PROTECTED] ,  Email(Personal) :- 
> [EMAIL PROTECTED]
>
>
> 
> DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{dropped}}
>
> __
> 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.


Re: [R] aggregate function

2007-04-23 Thread Martin Becker
If "monthly" should aggregate per "-mm" combination, you could try 
something like

   aggregate(x$z,list(cut(as.Date(x$Date),"m")),mean)

for monthly aggregation and

   aggregate(x$z,list(cut(as.Date(x$Date),"y")),mean)

for yearly means.
If monthly aggregation should aggregate over different years (and 
produce only 12 numbers), maybe

   aggregate(x$z, list(format(as.Date(x$Date),"%m")),mean)

works (everything untested).
Be sure to use R 2.4.1 patched or 2.5.0, since there was a bug in 
cut.Date which prevents the yearly aggregation from working properly 
before R 2.4.1 patched!

Regards,

  Martin

Michel Schnitz wrote:
> Hello,
>
> is there a way to use the aggregate function to calculate monthly mean 
> in case i have one row in data frame that holds the date like 
> -mm-dd? i know that it works for daily means. i also like to do it 
> for monthly and yearly means. maybe there is something like aggregate(x, 
> list(Date[%m]), mean)?
> the data frame looks like:
>
> Date  Timez
> 2006-01-0121:00   6,2
> 2006-01-0122:00   5,7
> 2006-01-0123:00   3,2
> 2006-01-0200:00   7,8
> 2006-01-0201:00   6,8
> 2006-01-0202:00   5,6
> .
> .
> .
> 2007-03-3022:00   5,2
> 2007-03-3023:00   8,3
> 2007-03-3100:00   6,4
> 2007-03-3101:00   7,4
>
> thanks for help!
>

__
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] Jarque-Bera and rnorm()

2007-04-27 Thread Martin Becker
Murali Menon schrieb:
> Folks,
>
> I'm a bit puzzled by the fact that if I generate 100,000 standard 
> normal variates using rnorm() and perform the Jarque-Bera on the 
> resulting vector, I get p-values that vary drastically from run to 
> run. Is this expected? 
Yes.
> Surely the p-val should be close to 1 for each test?
No. The p-value should rather be uniformly distributed on [0;1]. You can try

library(lawstat)
ttt<-numeric(1000)
for (i in 1:length(ttt)) ttt[i]<-rjb.test(rnorm(1))$p.value
hist(ttt)

to confirm that the combination of rnorm and rjb.test seems to behave 
correctly here.

Regards,

  Martin

>
> Are 100,000 variates sufficient for this test?
>

[...]

> Please advise. Thanks,
>
> Murali
>
> _
> MSN is giving away a trip to Vegas to see Elton John.  Enter to win 
> today.
>
> 
>
> __
> 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.


Re: [R] subset

2007-05-04 Thread Martin Becker
elyakhlifi mustapha wrote:
> hello,
>
>   
>> subset(swiss, Agriculture > 60 & Examination != c(14,16), select = 
>> c(Agriculture,Examination,Catholic))
>> 

Try %in% :

subset(swiss, Agriculture > 60 & Examination %in% c(14,16), select = 
c(Agriculture,Examination,Catholic))

Agriculture Examination Catholic
Broye  70.2  1692.85
Glane  67.8  1497.16
Veveyse64.5  1498.61
Aubonne67.5  14 2.27
Rolle  60.8  16 7.72

Regards,

  Martin

>  Agriculture Examination Catholic
> Broye   70.2  16 3.30
> Glane   67.8  14 4.20
> Aigle   62.0  21 5.16
> Avenches60.7  19 5.23
> Cossonay69.3  22 5.62
> Echallens   72.6  18 6.10
> Lavaux  73.0  19 9.96
> Oron71.2  1216.92
> Paysd'enhaut63.5   624.20
> Conthey 85.9   358.33
> Entremont   84.9   784.84
> Herens  89.7   590.57
> Martigwy78.2  1291.38
> Monthey 64.9   792.85
> St Maurice  75.9   993.40
> Sierre  84.6   396.83
> Sion63.1  1397.16
> Warning message:
> la longueur de l'objet le plus long
> n'est pas un multiple de la longueur de l'objet le plus court in: 
> Examination != c(14, 16) 
>
> As this example shows I'd like to know if it's possible to drop several lines 
> for example here to drop severals lines from Examination
> thanks
>
>
>   
> ___
>
>
>
>
>
>   [[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.


Re: [R] subset

2007-05-04 Thread Martin Becker
Sorry,

of course it should read

 > subset(swiss, Agriculture > 60 & !(Examination %in% c(14,16)), select 
= c(Agriculture,Examination,Catholic))
 Agriculture Examination Catholic
Aigle   62.0  21 8.52
Avenches60.7  19 4.43
Cossonay69.3  22 2.82
Echallens   72.6  1824.20
Lavaux  73.0  19 2.84
Oron71.2  12 2.40
Paysd'enhaut63.5   6 2.56
Conthey 85.9   399.71
Entremont   84.9   799.68
Herens  89.7   5   100.00
Martigwy78.2  1298.96
Monthey 64.9   798.22
St Maurice  75.9   999.06
Sierre  84.6   399.46
Sion63.1  13    96.83


Martin Becker wrote:
>
> [...]

__
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] I made some progress on my previous "systemfit" question but still not quite there

2007-05-24 Thread Martin Becker
Leeds, Mark (IED) schrieb:
> Surprisingly, I played around with some test code and below actually
> creates equations that look correct.
>
> tempmat<-matrix(10,nrow=6,ncol=6)
> restrictmat<-diag(6)
>
> colnames(tempmat)<-c("AUD.l1","CHF.l1","CAD.l1","GBP.l1","EUR.l1","JPY.l
> 1")
> rownames(tempmat)<-c("AUD","CHF","CAD","GBP","EUR","JPY")
>
> eqn<-list()
>
> for ( i in 1:6 ) {
>
> datares <- tempmat[, which(restrictmat[i, ] == 1),drop=FALSE]
> eqn[[i]]<-paste(rownames(tempmat)[i]," ~","-1","+",colnames(datares))
>
> print(eqn[[i]])
>
> }
>
> The only problem now is that I don't know how to name them so that
> I can do the
>
> system<-list( demand = eqDemand, supply = eqSupply)
>
> part that systemfit needs. In fact,  I don't know how to name the actual
> equation eqDemand or the named part demand.
>
>   

I am not sure, what you want to do exactly, but I suppose you need
   eqn <- lapply(eqn,as.formula)
somewhere after creating eqn. You can assign names to the equations via
  names(eqn),
but this is not necessary, you can simply pass the equations with
  systemfit(eqns=eqn...),
and optionally specify the names of the equations with eqnlabels= 
instead.

If you want multiple systemfit calls for subsets of the equations, you 
should be able to select the equations via [], e.g.,
eqns=eqn[1:2] for the first and second equation.

HTH,

  Martin

> I would want demand to be "AUD", supply to be "CHF", etc. If someone has
> time to run the code, they would see what I mean. 
> Thanks a lot.
> 
>
> This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
>
> __
> 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.


Re: [R] fSeries - Ox - ver: 240.10068 - Steps to make it work

2007-06-16 Thread Martin Becker
I think there is still a small bug which I reported some time ago to 
r-sig-finance 
(https://stat.ethz.ch/pipermail/r-sig-finance/2005q4/000498.html) and 
which takes effect if the time series is not stored in the variable 'x':

The line

write(x, file = "OxSeries.csv", ncolumns = 1, append = TRUE)

in .garchOxFit() (fSeries version 240.10068) should read

write(x = series, file = "OxSeries.csv", ncolumns = 1, append = TRUE)

instead.

Incorporating the changes for [EMAIL PROTECTED] could be a good occasion to 
fix this as well :-)

Regards,

  Martin


Ian Gregory wrote:
> -Bugs and fixes reported to Diethelm Wuertz.
> -In the interim.  To make the Ox functions part of the fSeries package work 
> please follow the following steps.
>
>   
[snip]

__
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] fSeries - Ox - ver: 240.10068 - Steps to make it work

2007-06-16 Thread Martin Becker
Line number 55 in the original mail from 2005 was a reference to 
garchOxFit (not .garchOxFit) in fSeries version 220.10063 (not 
240.10068), as mentioned in 
https://stat.ethz.ch/pipermail/r-sig-finance/2005q4/000498.html . Of 
course, in the current version of .garchOxFit, the line number has 
changed, but the line should still be there, and if .garchOxFit has less 
than 55 lines, it should be easy to find.
Does your example still work, if you don't have a variable 'x' visible 
to garchOxFit (in your environment/search path)? I suppose garchOxFit 
just uses the series stored in 'x' (in your current workspace) instead 
of 'IanSeries' (which is even worse than aborting...).

Regards,

  Martin


Ian Gregory schrieb:
> I tried the following and it works for me (after the changes to make):
>
> library(fSeries)
> data(dem2gbp)
> IanSeries = dem2gbp[, 1]
> garchOxFit(~garch(1,1),IanSeries)
>
> Any writing of data is performed in the GarchOxModelling.ox file.
> The number of lines of code in the function .garchOxFit() does not appear
> to go up to 55.  When using:  edit(garchOxFit).
>
> I get for the output from the estimation to be:
>
> ...
> ...
> Estimated Parameters Vector :
> -0.006183; 0.010761; 0.153406; 0.805877
>
>
> regards,
>
> Ian.
>
>
> - Original Message - From: "Martin Becker" 
> <[EMAIL PROTECTED]>
> To: "Ian Gregory" <[EMAIL PROTECTED]>
> Cc: ; <[EMAIL PROTECTED]>
> Sent: Saturday, June 16, 2007 8:31 PM
> Subject: Re: [R] fSeries - Ox - ver: 240.10068 - Steps to make it work
>
>
>> I think there is still a small bug which I reported some time ago to 
>> r-sig-finance 
>> (https://stat.ethz.ch/pipermail/r-sig-finance/2005q4/000498.html) and 
>> which takes effect if the time series is not stored in the variable 'x':
>>
>> The line
>>
>>write(x, file = "OxSeries.csv", ncolumns = 1, append = TRUE)
>>
>> in .garchOxFit() (fSeries version 240.10068) should read
>>
>>write(x = series, file = "OxSeries.csv", ncolumns = 1, append = TRUE)
>>
>> instead.
>>
>> Incorporating the changes for [EMAIL PROTECTED] could be a good occasion to 
>> fix this as well :-)
>>
>> Regards,
>>
>>  Martin
>>
>>
>> Ian Gregory wrote:
>>> -Bugs and fixes reported to Diethelm Wuertz.
>>> -In the interim.  To make the Ox functions part of the fSeries 
>>> package work please follow the following steps.
>>>
>>>
>> [snip]
>>
>>

__
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] How do I avoid a loop?

2007-06-19 Thread Martin Becker
Gabor Grothendieck wrote:
> xx is 1 in every position of the first run of TRUE, 2 in every
> position in the 2nd run of TRUE and so on.  The parenthesized
> expression in the second line converts those to increasing
> values and multiplying it by x zaps the garbage in the positions
> that correspond to FALSE in x.
>
> xx <- cumsum(diff(c(FALSE, x)) > 0)
> (seq_along(x) - match(xx, xx) + 1) * x
>
>   

If speed is a critical issue, there is another possibility. Thanks to 
Oleg Sklyar's "inline"-package, embedding C code is now quite easy:

library(inline)
code <- readLines(textConnection("
  SEXP res;
  PROTECT(res=allocVector(INTSXP,LENGTH(a)));
  int i,j=0;
  int *result = INTEGER(res);
  int *input  = INTEGER(a);
  for (i=0;i On 6/19/07, Feng, Ken <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>>
>> I start with an array of booleans:
>>
>>x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE );
>>
>> I want to define an y <- f(x) such that:
>>
>>y <- c( 1, 2, 3, 0, 0, 1, 2, 0, 1 );
>>
>> In other words, do a cumsum when I see a TRUE, but reset to 0 if I see a 
>> FALSE.
>>
>> I know I can do this with a very slow and ugly loop or maybe use apply,
>> but I was hoping there are some R experts out there who can show me
>> a cleaner/more elegant solution?
>>
>> Thanks in advance.
>>
>> - Ken
>>
>> __
>> 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@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] How do I avoid a loop?

2007-06-19 Thread Martin Becker
Gabor Grothendieck wrote:
> xx is 1 in every position of the first run of TRUE, 2 in every
> position in the 2nd run of TRUE and so on.  The parenthesized
> expression in the second line converts those to increasing
> values and multiplying it by x zaps the garbage in the positions
> that correspond to FALSE in x.
>
> xx <- cumsum(diff(c(FALSE, x)) > 0)
> (seq_along(x) - match(xx, xx) + 1) * x
>
>
>   

If speed is a critical issue, there is another possibility. Thanks to 
Oleg Sklyar's "inline"-package, embedding C code is now quite easy:

library(inline)
code <- readLines(textConnection("
 SEXP res;
 PROTECT(res=allocVector(INTSXP,LENGTH(a)));
 int i,j=0;
 int *result = INTEGER(res);
 int *input  = INTEGER(a);
 for (i=0;i On 6/19/07, Feng, Ken <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>>
>> I start with an array of booleans:
>>
>>x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE );
>>
>> I want to define an y <- f(x) such that:
>>
>>y <- c( 1, 2, 3, 0, 0, 1, 2, 0, 1 );
>>
>> In other words, do a cumsum when I see a TRUE, but reset to 0 if I see a 
>> FALSE.
>>
>> I know I can do this with a very slow and ugly loop or maybe use apply,
>> but I was hoping there are some R experts out there who can show me
>> a cleaner/more elegant solution?
>>
>> Thanks in advance.
>>
>> - Ken
>>
>> __
>> 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@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] R file via SSH

2007-07-13 Thread Martin Becker
You may find "screen" useful, see e.g.

  http://tolstoy.newcastle.edu.au/R/e2/help/07/02/10824.html

for a short description how to use it with R (reattaching works via 
"screen -r"). (Maybe your sysadmin has to install screen first, it's a 
unix tool.)
KR

  Martin

[EMAIL PROTECTED] wrote:
> Goodmorning everybody,
> I need to run an R program via SSH. Usually I open R, I run the 
> program and I stay logged-in, waiting for the output. As a matter of 
> fact, if I close the connection with SSH I loose the calculations and 
> the output of my R program. What command I have to use in order to 
> preseve the calculations and the output without staying logged-in a SSH 
> connection?
> thanks in advance
>
> Marialucia
>
>
> 
> TISCALI TANDEM FREE
> Telefono e Adsl 4 MB da € 22.95 al mese. Stacchi Telecom!
> GRATIS modem, segreteria e seconda linea telefonica!   
> http://abbonati.tiscali.it/adsl/prodotti/tc/tandemfree_tel/
>
> __
> 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.


Re: [R] R editor vs. Tinn-R

2007-01-12 Thread Martin Becker
Farrel Buchinsky wrote:
> Have you used Tinn-R and what landmines await the inexperienced?
>
>   

Depending on which button you press in Tinn-R, the clipboard is used to 
transfer the commands to R, so sometimes you can't rely on the previous 
contents of the clipboard while using Tinn-R. If you use the 
"(source)"-versions of the buttons, the content of the clipboard should 
be preserved.

Regards,
  Martin

> I could not understand why a script that used to work stopped working.
> Look at these two scenarios
> I opened an excel spreadsheet and copied several cells to the clipboard
> Then Scenario 1
> Executed from Tinn-R
>   
>> prelim<-read.delim("clipboard")
>> str(prelim)
>> 
> 'data.frame':   0 obs. of  1 variable:
>  $ prelim..read.delim.clipboard.: logi
>
> Scenario 2
> Executed from R editor
>   
>> prelim<-read.delim("clipboard")
>> str(prelim)
>> 
> 'data.frame':   18 obs. of  13 variables:
>
>

__
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] R editor vs. Tinn-R

2007-01-12 Thread Martin Becker
Zitat von Farrel Buchinsky <[EMAIL PROTECTED]>:

> The only button I pressed was the "send line" button in version 1.19.1.5. I
> changed my command to
>
> prelim<-read.delim(source("clipboard"))
>

The problem is not using the wrong R-command, but using a (Tinn-R)  
button that leads to a replacement of the current (windows) clipboard...

> and still got the same problem.
> I do not know how to use the source versions of the buttons. Can you please
> tell me more?
>

There are three button groups on the left of the "Send line" button,  
containing two buttons each. The left button of each of these three  
button groups has the same name as the right button of each group,  
apart from having a "(source)" suffix. Now it should be obvious what  
was meant with '"(source)"-version of buttons'. There is no such  
version for the "Send line" button, so you have to select the  
corresponding line and use the "Send selection (source)" button, e.g.

> Thanks
>
> Farrel
>

Regards,
   Martin

>
> "Martin Becker" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Farrel Buchinsky wrote:
>>> Have you used Tinn-R and what landmines await the inexperienced?
>>>
>>>
>>
>> Depending on which button you press in Tinn-R, the clipboard is used to
>> transfer the commands to R, so sometimes you can't rely on the previous
>> contents of the clipboard while using Tinn-R. If you use the
>> "(source)"-versions of the buttons, the content of the clipboard should
>> be preserved.
>>
>> Regards,
>>  Martin
>>
>>> I could not understand why a script that used to work stopped working.
>>> Look at these two scenarios
>>> I opened an excel spreadsheet and copied several cells to the clipboard
>>> Then Scenario 1
>>> Executed from Tinn-R
>>>
>>>> prelim<-read.delim("clipboard")
>>>> str(prelim)
>>>>
>>> 'data.frame':   0 obs. of  1 variable:
>>>  $ prelim..read.delim.clipboard.: logi
>>>
>>> Scenario 2
>>> Executed from R editor
>>>
>>>> prelim<-read.delim("clipboard")
>>>> str(prelim)
>>>>
>>> 'data.frame':   18 obs. of  13 variables:
>>>
>>>
>>
>> __
>> 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@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] R editor vs. Tinn-R

2007-01-12 Thread Martin Becker
Zitat von BBands <[EMAIL PROTECTED]>:

> On 1/12/07, Martin Becker <[EMAIL PROTECTED]> wrote:
>> Depending on which button you press in Tinn-R, the clipboard is used to
>> transfer the commands to R, so sometimes you can't rely on the previous
>> contents of the clipboard while using Tinn-R. If you use the
>> "(source)"-versions of the buttons, the content of the clipboard should
>> be preserved.
>
> Something odd is going on. I can confirm that read.delim("clipboard")
> works from R, but not from Tinn-R. What seems odd is that the contents
> of the clipboard _are_ preserved after the Tinn-R send, so that a
> subsequent paste or read.delim("clipboard") from R works correctly.
> Perhaps Tinn-R restores the contents of the clipboard after sending to
> R such that the R command runs before the restore takes place?
>

Sorry, my mistake: Apparently only "Send file (source)" preserves the  
clipboard while passing the source-command to R.
Regards,
   Martin

>  jab
> --
> John Bollinger, CFA, CMT
> www.BollingerBands.com
>
> If you advance far enough, you arrive at the beginning.
>
> __
> 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.


Re: [R] Kernel density output

2007-01-15 Thread Martin Becker
Florent Bresson schrieb:
> Hi, 
>
> I'm using the density() command for a given vector x and I would like to know 
> how to get the estimated value of the density for each element of the vector 
> x instead of values corresponding to points from a grid.
>
>   

Maybe not the best/most efficient way to do this, but

   splinefun(density(x))(x)

may work for you.
> Thanks
>
> Florent Bresson
>
>   
Regards,

  Martin
> __
> 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.


Re: [R] Row limit for read.table

2007-01-17 Thread Martin Becker
Frank McCown schrieb:
> I have been trying to read in a large data set using read.table, but 
> I've only been able to grab the first 50,871 rows of the total 122,269 rows.
>
>  > f <- 
> read.table("http://www.cs.odu.edu/~fmccown/R/Tchange_rates_crawled.dat";, 
> header=TRUE, nrows=123000, comment.char="", sep="\t")
>  > length(f$change_rate)
> [1] 50871
>
>  From searching the email archives, I believe this is due to size limits 
> of a data frame.  So...
>
>   
It is not due to size limits, see below.
> 1) Why doesn't read.table give a proper warning when it doesn't place 
> every read item into a data frame?
>
>   
In your case, read.table behaves as documented.
The ' - character is one of the standard quoting characters. Some (but 
very few) of the entrys contain single ' chars, so sometimes more than 
ten thousand lines are just treated as a single entry. Try using 
quote="" to disable quoting, as documented on the help page:

f<-read.table("http://www.cs.odu.edu/~fmccown/R/Tchange_rates_crawled.dat";,
header=TRUE, nrows=123000, comment.char="", sep="\t",quote="")

length(f$change_rate)
[1] 122271

> 2) Why isn't there a parameter to read.table that allows the user to 
> specify which columns s/he is interested in?  This functionality would 
> allow extraneous columns to be ignored which would improve memory usage.
>
>   
There is (colClasses, works as documented). Try

 f<-read.table("http://www.cs.odu.edu/~fmccown/R/Tchange_rates_crawled.dat";, 

+ header=TRUE, nrows=123000, comment.char="", 
sep="\t",quote="",colClasses=c("character","NULL","NULL","NULL","NULL"))
 > dim(f)
[1] 122271  1

> I've already made a work-around by loading the table into mysql and 
> doing a select on the 2 columns I need.  I just wonder why the above 2 
> points aren't implemented.  Maybe they are and I'm totally missing it.
>
>   
Did you read the help page?
> Thanks,
> Frank
>
>
>   
Regards,
   Martin

__
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] How to optimize this loop ?

2007-01-18 Thread Martin Becker
Petr Pikal schrieb:
> Hi
>
> discard your loop do not optimise it.
> rle is your friend
>   
I do not agree. For some purposes, an efficient loop is faster. IMHO 
this is one of these purposes.
I propose the following modification of the loop (to increase speed):

myfun1 <- function(series=c(3, 4, 10,14,8,3,4,6,9)) {
  len<-length(series)
  for (i in (len-1):1)
  {
if (series[i]>series[len])
{ result <- i-1 ; break }
  }
  return(result)
}

The speed measurement, in comparison with the rle approach:

 > system.time(for (i in 1:1) erg<-my_fun(c(3, 4, 10,14,8,3,4,6,9)))
[1] 4.48 0.00 4.48   NA   NA

 > system.time(for (i in 1:1) erg<-myfun1(c(3, 4, 10,14,8,3,4,6,9)))
[1] 0.33 0.00 0.33   NA   NA

Regards, Martin
>   
>> my_fun<-function(x) {
>> 
> + 
> + len<-length(x)
> + x1<-rle(x[len]>x[1:len-1])
> + last<-length(x1$values)
> + ifelse(x1$values[last],x1$lengths[last],0)
> + }
>   
>> my_fun(my_series)
>> 
> [1] 0
>   
>> my_series <- c(3, 4, 10,14,8,3,4,6,9)
>> my_fun(my_series)
>> 
> [1] 4
>   
>
> and vectorise, vectorise, vectorise.
>
> HTH
> Petr
>
>
>
>
> On 18 Jan 2007 at 14:11, Nicolas Prune wrote:
>
> Date sent:Thu, 18 Jan 2007 14:11:11 +0100
> From: Nicolas Prune <[EMAIL PROTECTED]>
> To:   r-help@stat.math.ethz.ch
> Subject:  [R] How to optimize this loop ?
>
>   
>> Dear R Users,
>>
>> I request your help to optimize a loop.
>>
>> Given a series of observations, I want to know how many consecutive
>> past observations are below the last one.
>>
>> e.g :
>> my_series <- c(3, 4, 10,14,8,3,4,6,9)
>>
>> As the last number (9)  is higher than the four preceding numbers (6,
>> 4, 3, 8), this function should return 4.
>>
>> my_series <- c(3, 4, 10,14,8,3,4,11,9)
>> Here, it should return 0, as 9 is immediately preceeded by a higher
>> number.
>>
>> So far, I do this awful loop :
>>
>> result <- 0
>> for (i in 1:length(my_series-1))
>> {
>>  if (my_series[length(my_series)-i]>end(my_series)[1])
>> { result <- i-1 ; break }
>> }
>>
>> I thing there's a better way...
>>
>> my_series > my_series[end][1] returns :
>> TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE
>> , which seems more appealing (once the last "FALSE" is removed), but
>> now, how to know the size of the last consecutive series of "TRUE" ?
>>
>> Can you see a better way ?
>>
>> Thanks.
>>
>> __
>> 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.
>> 
>
> Petr Pikal
> [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.
>

__
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] How to optimize this loop ? (correction)

2007-01-18 Thread Martin Becker
Sorry, I accidentaly lost one line of the function code (result <-0), 
see below...
Regards, Martin

Martin Becker schrieb:
>
> myfun1 <- function(series=c(3, 4, 10,14,8,3,4,6,9)) {
 result <- 0# NEW
>  len<-length(series)
>  for (i in (len-1):1)
>  {
>if (series[i]>series[len])
>{ result <- i-1 ; break }
>  }
>  return(result)
> }
>
...

__
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] jump in sequence

2007-01-30 Thread Martin Becker
Adrian DUSA wrote:
> Dear list,
>
> This should be a simple one, I just cannot see it.
> I need to generate a sequence of the form:
> 4  5  6 13 14 15 22 23 24
>
> That is: starting with 4, make a 3 numbers sequence, jump 6, then another 3
> and so on.
> I can create a whole vector with:
> myvec <- rep(rep(c(F, T, F), rep(3, 3)), 3)
>
> Then see which are TRUE:
> which(myvec)
> [1]  4  5  6 13 14 15 22 23 24
>
>
> I'd like to avoid creating the whole vector if possible; for very large ones
> it can be time consuming. There should be a way to only create the proper
> indexes...
>
>   
Maybe:

n=10
3+rep(1:3,times=n)+9*rep(0:(n-1),each=3)

> Thanks for any hint,
> Adrian
>
>   

Regards,
  Martin

__
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.