clangkamp | 1 Dec 2010 01:04
Picon
Picon

Re: Can't Destroy Dim Names


Dear David
To confirm, your method worked. I am not allowed to divulge the original
data (financial data), but here comes another set.

Test_DF<-data.frame(Figure=c("A","B","A","B"), Code=c("C", "C", "D", "D"),
No=c(1,2,3.5,4))
?data.frame
View(Test_DF)
str(Test_DF)
Test_DF_m<-melt(Test_DF, measure="No")
View(Test_DF_m)
Test_DF_c<-cast(Test_DF_m, Figure~Code)
str(Test_DF_c)

Basically, after the casting the variables the naming appears. If one then
goes forth with this item, and does some operations on them (in my case with
the zoo package), and ends up with the same cube, but just chr as row/column
names but actually the same ones and then tries to merge them (abind). The
set above doesn't replicate strangely everything my set does, ind adds a lot
more attributes even though I go through the same commands.

So the bottom line is where I would expect a simple 2 by 2 matrix with row
and column names after the melt and cast, it is a much more complex object
and I think tearing off all the rest might be a good thing before
proceeding. This is the background to the question.

-----
Christian Langkamp
christian.langkamp-at-gmxpro.de
(Continue reading)

Romildo Martins | 1 Dec 2010 01:18
Picon

Filter a Matrix

Hello,

How to filter the matrix (m) based on the array (a)?

> m
     [,1] [,2] [,3]
[1,]    5    1    4
[2,]    2    6    2
[3,]    3    4    7
[4,]    1    2    6
[5,]    1    5    3
[6,]    7    6    2

> a
[1] 2 6

> output
     [,1] [,2] [,3]
[1,]    2    6    2
[2,]    1    2    6
[3,]    7    6    2

Thanks a lot!

RMB

	[[alternative HTML version deleted]]

Peter Ehlers | 1 Dec 2010 01:18
Picon
Favicon

Re: rcauchy density distribution

On 2010-11-30 15:52, David Hervas Marin wrote:
> Hello, I'm taking samples from certain distributions and drawing a density
> distribution over the histogram of the samples
> It works fine for the chi-square and for the normal, but not for the cauchy. Any
> idea what I'm doing wrong? Thanks

Not doing anything wrong, really. But do check

  range(x)

Should be quite a range; that's what 'heavy tails' means.
To see the fit, try this:

  hist(x, freq=FALSE, breaks=5000, xlim=c(-6,6))
  curve(dcauchy(x), col = 2, add = TRUE)

Peter Ehlers

>
> x<- rchisq(10000, df = 4)
> hist(x, freq = FALSE, breaks=100)
> curve(dchisq(x, df = 4), col = 2, add = TRUE)
>
> x<- rnorm(10000)
> hist(x, freq = FALSE, breaks=100)
> curve(dnorm(x), col = 2, add = TRUE)
>
> x<- rcauchy(10000)
> hist(x, freq = FALSE, breaks=100)
> curve(dcauchy(x), col = 2, add = TRUE)
(Continue reading)

Jorge Ivan Velez | 1 Dec 2010 01:30
Picon

Re: Filter a Matrix

Hi Romildo,

One possible way would be the following:

index <- apply(m, 1, function(row) any(a %in% row))
m[index, ]

HTH,
Jorge

On Tue, Nov 30, 2010 at 7:18 PM, Romildo Martins <> wrote:

> Hello,
>
> How to filter the matrix (m) based on the array (a)?
>
> > m
>     [,1] [,2] [,3]
> [1,]    5    1    4
> [2,]    2    6    2
> [3,]    3    4    7
> [4,]    1    2    6
> [5,]    1    5    3
> [6,]    7    6    2
>
> > a
> [1] 2 6
>
> > output
>     [,1] [,2] [,3]
(Continue reading)

Ben Bolker | 1 Dec 2010 01:37
Picon

Re: Filter a Matrix

Jorge Ivan Velez <jorgeivanvelez <at> gmail.com> writes:

> 
> Hi Romildo,
> 
> One possible way would be the following:
> 
> index <- apply(m, 1, function(row) any(a %in% row))
> m[index, ]
> 
> HTH,
> Jorge
> 

  Does the original poster mean 

 index <- apply(m, 1, function(row) all(a %in% row))
 m[index, ]

?

A little hard to tell because in the original example 'all'
and 'any' would give the same answers -- 2 and 6 always occur
together.

Jason Edgecombe | 1 Dec 2010 02:27

How to draw a rect() behind a hist() ?

Hi,

I have the following code:

hist(gps$heartpercent, breaks=5)
rect(90, par("usr")[3], 100, par("usr")[4], col = "red")

How do I get the rectangle to appear behind the histogram. Barring that, 
how can I make certain bars of the histogram to be a certain color?

Thanks,
Jason

Santosh Srinivas | 1 Dec 2010 03:04
Picon

Difference between loops and vectorization

Hello R-helpers,

A fundamental question ...I'm trying to understand the differences
between loop and vectorization ... I understand that it should be a
natural choice to use apply / adply when it is needed to perform the
same function across all rows of a data frame.
Any pointers on why this is so? Unable to find the right reading place
on the WWW which explains the concept.

Thanks for your help.
S

Bill Yang | 1 Dec 2010 03:40
Picon
Favicon

Re: Welcome to the "R-help" mailing list


Hi there,
I am having problem of matching string. what i want is when i type a date such as 2010-11-30, the function will
return the day (monday, tuesday, wednesday, thursday, friday or staturday). then i want another
function will return true if the return of the day is monday, return false if the return of the day is not monday.
I already find the weekdays(as.Date('2010-11-30')) function which will tell me exactly what day its
gonna be. however, i am having problem of return True or False whether or not the return day has matched. 
please help me out. I appreciate.
Bill
P.S the following is the partial codes.if(match(weekdays(as.Date('2010-11-30'), "Monday")==1){print("yes")}

r-help <at> r-project.org
> Subject: Welcome to the "R-help" mailing list
> From: r-help-request <at> r-project.org
> To: gy631223 <at> hotmail.com
> Date: Wed, 1 Dec 2010 03:34:01 +0100
> 
> Welcome to the R-help <at> r-project.org mailing list!
> 
> To post to this list, send your email to:
> 
>   r-help <at> r-project.org
> 
> General information about the mailing list is at:
> 
>   https://stat.ethz.ch/mailman/listinfo/r-help
> 
> If you ever want to unsubscribe or change your options (eg, switch to
> or from digest mode, change your password, etc.), visit your
> subscription page at:
(Continue reading)

Luis Felipe Parra | 1 Dec 2010 03:56
Picon

Changing the day of the month in a date

Hello, I want to change the day of the month in a date object. What I am
doing at the moment is:

x=as.POSIXlt(x)
x$mday=13
x=as.Date(x)

Does anybody know if there is a more "natural" (eficient) way to do this

Thank you

Felipe Parra

	[[alternative HTML version deleted]]

Ista Zahn | 1 Dec 2010 03:59
Picon
Favicon

Re: Welcome to the "R-help" mailing list

Hi Bill,
You might be working too hard. Consider:
> weekdays(as.Date('2010-11-30')) == "Monday"
[1] FALSE
> weekdays(as.Date('2010-11-29')) == "Monday"
[1] TRUE
>

HTH,
Ista

On Tue, Nov 30, 2010 at 9:40 PM, Bill Yang <gy631223 <at> hotmail.com> wrote:
>
> Hi there,
> I am having problem of matching string. what i want is when i type a date such as 2010-11-30, the function
will return the day (monday, tuesday, wednesday, thursday, friday or staturday). then i want another
function will return true if the return of the day is monday, return false if the return of the day is not monday.
> I already find the weekdays(as.Date('2010-11-30')) function which will tell me exactly what day its
gonna be. however, i am having problem of return True or False whether or not the return day has matched.
> please help me out. I appreciate.
> Bill
> P.S the following is the partial codes.if(match(weekdays(as.Date('2010-11-30'), "Monday")==1){print("yes")}
>
>
>
> r-help <at> r-project.org
>> Subject: Welcome to the "R-help" mailing list
>> From: r-help-request <at> r-project.org
>> To: gy631223 <at> hotmail.com
>> Date: Wed, 1 Dec 2010 03:34:01 +0100
(Continue reading)


Gmane