[R] Concatenate two lists, list by list

2013-01-22 Thread Alaios
Dear all,
I would like to concatenate the lists below

str(Part2$dataset)
List of 3
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...



str(Part1$dataset)
List of 3
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...


I tried concatenating those with:


> str(cbind(Part1$datase,Part2$dataset))
List of 6
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dim")= int [1:2] 3 2


but I want something different. To concatenate those into  a list by list 
operation so I will end up with something looking like that

str(concatenatedLists)

List of 3
 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dim")= int [1:2] 3 2


Is there anything that can do that in R?

Regards
Alex
[[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] Concatenate two lists, list by list

2013-01-23 Thread Alaios
Thanks a lot Petr,
for the answer
unfortunately that would convert everything to a matrix

num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ...

but if you check below you can see that I Want those to form a list.

Regards
Alex





 From: PIKAL Petr 

Sent: Tuesday, January 22, 2013 11:51 AM
Subject: RE: [R] Concatenate two lists, list by list

Hi

Maybe you could use mapply

mapply(c, Part1$dataset,Part2$dataset)

Regards
Petr

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Alaios
> Sent: Tuesday, January 22, 2013 11:26 AM
> To: R help
> Subject: [R] Concatenate two lists, list by list
> 
> Dear all,
> I would like to concatenate the lists below
> 
> str(Part2$dataset)
> List of 3
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
> 
> 
> 
> str(Part1$dataset)
> List of 3
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
> 
> 
> I tried concatenating those with:
> 
> 
> > str(cbind(Part1$datase,Part2$dataset))
> List of 6
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>  - attr(*, "dim")= int [1:2] 3 2
> 
> 
> but I want something different. To concatenate those into  a list by
> list operation so I will end up with something looking like that
> 
> str(concatenatedLists)
> 
> List of 3
>  $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>  $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>  - attr(*, "dim")= int [1:2] 3 2
> 
> 
> Is there anything that can do that in R?
> 
> Regards
> Alex
>     [[alternative HTML version deleted]]
[[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] Concatenate two lists, list by list

2013-01-23 Thread Alaios
Thanks a lot.
Unfortunately that did not help either.

num [1:32003, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:32003] "" "" "" "" ...
  ..$ : NULL

but I want to get

>> List of 3
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   - attr(*, "dim")= int [1:2] 3 2
>>



I am sorry that I can not find  reproducible example to show you

Alex




 From: D. Rizopoulos 

Cc: PIKAL Petr ; R help  
Sent: Wednesday, January 23, 2013 11:08 AM
Subject: Re: [R] Concatenate two lists, list by list

you just need:

mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE)


I hope it helps.

Best,
Dimitris


On 1/23/2013 11:01 AM, Alaios wrote:
> Thanks a lot Petr,
> for the answer
> unfortunately that would convert everything to a matrix
>
> num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
>
> but if you check below you can see that I Want those to form a list.
>
> Regards
> Alex
>
>
>
>
> 
>   From: PIKAL Petr 
>
> Sent: Tuesday, January 22, 2013 11:51 AM
> Subject: RE: [R] Concatenate two lists, list by list
>
> Hi
>
> Maybe you could use mapply
>
> mapply(c, Part1$dataset,Part2$dataset)
>
> Regards
> Petr
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Alaios
>> Sent: Tuesday, January 22, 2013 11:26 AM
>> To: R help
>> Subject: [R] Concatenate two lists, list by list
>>
>> Dear all,
>> I would like to concatenate the lists below
>>
>> str(Part2$dataset)
>> List of 3
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>
>>
>>
>> str(Part1$dataset)
>> List of 3
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>
>>
>> I tried concatenating those with:
>>
>>
>>> str(cbind(Part1$datase,Part2$dataset))
>> List of 6
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ...
>>   - attr(*, "dim")= int [1:2] 3 2
>>
>>
>> but I want something different. To concatenate those into  a list by
>> list operation so I will end up with something looking like that
>>
>> str(concatenatedLists)
>>
>> List of 3
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ...
>>   - attr(*, "dim")= int [1:2] 3 2
>>
>>
>> Is there anything that can do that in R?
>>
>> Regards
>> Alex
>>      [[alternative HTML version deleted]]
>     [[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.
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
[[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] Plot a Matrix as an Image with ggplot

2013-02-14 Thread Alaios
Dear all,
I am trying to plot a matrix I have  as an image

str(matrixToPlot)
 num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .


 that contains only 0s and 1s,


where the xlabel will be Labeled as 
str(xLabel)
 num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...

and the yLabels will be labeled as
str(yLabel)
 num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...


I have found on the internet that I can do something like that with ggplot2.
For example
you can run the following



library(reshape2)library(ggplot2)m 
=matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()

What I see missing here is to get my matrix and transform it to a data frame 
with labels for x and y axis so as ggplot can print the values nice. If you get 
the idea this matrix will be printed as a two tile pattern let's say with black 
tiles zeros and white tiles black where a color bar will depicting that black 
means zero and white one.

To help you with my code you will find attached the three items I have 
discussed here, the matrix, the x and the y labels.

Could you please help me with that?

Alex__
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] Format Integers

2013-02-14 Thread Alaios
Dear all,
I would like to format the following numbers

xLabel
 [1] 10 1000153846 1000307692 1000461538 1000615385 1000769231
 [7] 1000923077 1001076923 1001230769 1001384615 1001538462 1001692308
[13] 1001846154 100200 1002153846 1002307692 1002461538 1002615385
[19] 1002769231 1002923077 1003076923 1003230769 1003384615 1003538462
[25] 1003692308 1003846154 100400 1004153846 1004307692 1004461538
[31] 1004615385 1004769231 1004923077 1005076923 1005230769 1005384615
[37] 1005538462 1005692308 1005846154 100600 1006153846 1006307692
[43] 1006461538 1006615385 1006769231 1006923077 1007076923 1007230769
[49] 1007384615 1007538462 1007692308 1007846154 100800 1008153846
[55] 1008307692 1008461538 1008615385 1008769231 1008923077 1009076923
[61] 1009230769 1009384615 1009538462 1009692308 1009846154 101000


that are in watts to megawatts so they appear (as an example)


from: 1009846154 to 1009.846154 and even better to truncate it a bit to look 
better as

   1009.84 

Could you please help with the formatting ?

Regards
Alex
[[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] Plot a Matrix as an Image with ggplot

2013-02-14 Thread Alaios


Hi,
thanks
I changed slightly the code to be reproducible from everyone . I have  tried 
ggplot
but I need a bit of help to tweak it a bit

So you can run the following in your computer

  testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(1:5,1:5))

  p<-ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
ylab("Threshold") +    geom_raster()


  p


What I want to improve is
a: make the colorbar so only two specific colors lets say black and white and 
only two values 0 and 1 and somewhere the string as title of the color bar 
"text" to appear.

I have tried something like
p+   scale_color_gradient(low="red",high="blue")
Fehler in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0


ggplot(melt(testData), aes(Var2,Var1, fill=value,colorbin=2))+xlab("MHz") + 
ylab("Threshold") +    geom_raster()
but this did not affect colorbar entries.


b. reduce/remove the grayish border that appears between the legend and the 
image plot

Could you please help me with these two?

Regards
Alex




From: John Kane 
To: Alaios ; R help  
Sent: Thursday, February 14, 2013 4:35 PM
Subject: RE: [R] Plot a Matrix as an Image with ggplot

The R-help list is rather picky about what attached. None of your attachments 
arrived. 

The str() info is useful but please supply some sample data 

The easiest way to supply data  is to use the dput() function.  Example with 
your file named "testfile": 
dput(testfile) 

Then copy the output and paste into your email.  For large data sets, you can 
just supply a representative sample.  Usually, 
dput(head(testfile, 100)) will be sufficient.  

How are you writing the code/or what format is the original email. Your code in 
the body of the text is badly messed up -- you probably need to post only in 
text. HTML etc is automatically dropped.




John Kane
Kingston ON Canada


> -Original Message-
> From: ala...@yahoo.com
> Sent: Thu, 14 Feb 2013 07:15:05 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] Plot a Matrix as an Image with ggplot
> 
> Dear all,
> I am trying to plot a matrix I have  as an image
> 
> str(matrixToPlot)
>  num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
> 
> 
>  that contains only 0s and 1s,
> 
> 
> where the xlabel will be Labeled as
> str(xLabel)
>  num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
> 
> and the yLabels will be labeled as
> str(yLabel)
>  num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
> 
> 
> I have found on the internet that I can do something like that with
> ggplot2.
> For example
> you can run the following
> 
> 
> 
> library(reshape2)library(ggplot2)m
> =matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()
> 
> What I see missing here is to get my matrix and transform it to a data
> frame with labels for x and y axis so as ggplot can print the values
> nice. If you get the idea this matrix will be printed as a two tile
> pattern let's say with black tiles zeros and white tiles black where a
> color bar will depicting that black means zero and white one.
> 
> To help you with my code you will find attached the three items I have
> discussed here, the matrix, the x and the y labels.
> 
> Could you please help me with that?
> 
> Alex


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!
Check it out at http://www.inbox.com/marineaquarium

__
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] Plot a Matrix as an Image with ggplot

2013-02-15 Thread Alaios
You were right,
the following two work


testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(Var1=c(1:5),Var2=c(1:5)))
 ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
ylab("Threshold") +    geom_raster() + scale_fill_gradient(low="#FF", 
high="#00")



still there are two minor unresolved issues.

a. How to reduce the extra space in the plot between legend and the tiles?
b. How to make color bar depict only the two values of the game, 0 and 1 , 
instead of 0, 0.25, 0.50, 0.75, 1?

I would like to thank you in advanec for your help
Regards
Alex


- Original Message -
From: Dennis Murphy 
To: Alaios 
Cc: 
Sent: Friday, February 15, 2013 10:19 AM
Subject: Re: [R] Plot a Matrix as an Image with ggplot

Your aesthetic is fill, not color. Change scale_color_gradient to
scale_fill_gradient and you'll get what you expect.

D.

On Thu, Feb 14, 2013 at 11:31 PM, Alaios  wrote:
>
>
> Hi,
> thanks
> I changed slightly the code to be reproducible from everyone . I have  tried 
> ggplot
> but I need a bit of help to tweak it a bit
>
> So you can run the following in your computer
>
>   testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(1:5,1:5))
>
>   p<-ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
>ylab("Threshold") +    geom_raster()
>
>
>   p
>
>
> What I want to improve is
> a: make the colorbar so only two specific colors lets say black and white and 
> only two values 0 and 1 and somewhere the string as title of the color bar 
> "text" to appear.
>
> I have tried something like
> p+   scale_color_gradient(low="red",high="blue")
> Fehler in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
>
>
> ggplot(melt(testData), aes(Var2,Var1, fill=value,colorbin=2))+xlab("MHz") + 
> ylab("Threshold") +    geom_raster()
> but this did not affect colorbar entries.
>
>
> b. reduce/remove the grayish border that appears between the legend and the 
> image plot
>
> Could you please help me with these two?
>
> Regards
> Alex
>
>
>
> 
> From: John Kane 
> To: Alaios ; R help 
> Sent: Thursday, February 14, 2013 4:35 PM
> Subject: RE: [R] Plot a Matrix as an Image with ggplot
>
> The R-help list is rather picky about what attached. None of your attachments 
> arrived.
>
> The str() info is useful but please supply some sample data
>
> The easiest way to supply data  is to use the dput() function.  Example with 
> your file named "testfile":
> dput(testfile)
>
> Then copy the output and paste into your email.  For large data sets, you can 
> just supply a representative sample.  Usually,
> dput(head(testfile, 100)) will be sufficient.
>
> How are you writing the code/or what format is the original email. Your code 
> in the body of the text is badly messed up -- you probably need to post only 
> in text. HTML etc is automatically dropped.
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
>> -Original Message-
>> From: ala...@yahoo.com
>> Sent: Thu, 14 Feb 2013 07:15:05 -0800 (PST)
>> To: r-help@r-project.org
>> Subject: [R] Plot a Matrix as an Image with ggplot
>>
>> Dear all,
>> I am trying to plot a matrix I have  as an image
>>
>> str(matrixToPlot)
>>  num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
>>
>>
>>  that contains only 0s and 1s,
>>
>>
>> where the xlabel will be Labeled as
>> str(xLabel)
>>  num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
>>
>> and the yLabels will be labeled as
>> str(yLabel)
>>  num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
>>
>>
>> I have found on the internet that I can do something like that with
>> ggplot2.
>> For example
>> you can run the following
>>
>>
>>
>> library(reshape2)library(ggplot2)m
>> =matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()
>>
>> What I see missing here is to get my matrix and transform it to a data
>> frame with labels for x and y axis so as ggplot can print the values
>> nice. If you get the idea this matrix will be printed as a two tile
>> pattern let's say with black tiles zeros and white tiles black where a
>> color bar will depicting that black means zero and white one.
>>
>> To help you with my code you will find attached the three items I have
>> discussed here, the matrix, the x and the y labels.
>>
>> Could you please help me with that?
>>
>

Re: [R] Plot a Matrix as an Image with ggplot

2013-02-18 Thread Alaios
You are good!
Many thanks

Alex





 From: Dennis Murphy 

Cc: R help  
Sent: Saturday, February 16, 2013 3:11 AM
Subject: Re: [R] Plot a Matrix as an Image with ggplot

Hi:

See if the following works for you:

library(reshape2)
library(ggplot2)
tdm <- melt(testData)

ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
    labs(x = "MHz", y = "Threshold", fill = "Value") +
    geom_raster() +
    scale_fill_manual(breaks = levels(factor(tdm$value)),
                      values = c("white", "black")) +
    theme(plot.background = element_rect(fill = "grey90"),
          legend.background = element_rect(fill = "grey90")) +
    scale_x_continuous(expand = c(0, 0)) +
    scale_y_continuous(expand = c(0, 0))

It was necessary to create a different plot background color because
you wanted to remove the padding, which blended much of the plot
boundary with the original white background, and had to do something
similar to the legend background so that you could see the white
legend box.

The expand = c(0, 0) argument to the two scale functions answers your
second question, and converting value from numeric to vector answers
the first.

Dennis


> You were right,
> the following two work
>
>
> testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(Var1=c(1:5),Var2=c(1:5)))
>  ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
>ylab("Threshold") +    geom_raster() + scale_fill_gradient(low="#FF", 
>high="#00")
>
>
>
> still there are two minor unresolved issues.
>
> a. How to reduce the extra space in the plot between legend and the tiles?
> b. How to make color bar depict only the two values of the game, 0 and 1 , 
> instead of 0, 0.25, 0.50, 0.75, 1?
>
> I would like to thank you in advanec for your help
> Regards
> Alex
>
>
> - Original Message -
> From: Dennis Murphy 

> Cc:
> Sent: Friday, February 15, 2013 10:19 AM
> Subject: Re: [R] Plot a Matrix as an Image with ggplot
>
> Your aesthetic is fill, not color. Change scale_color_gradient to
> scale_fill_gradient and you'll get what you expect.
>
> D.
>

>>
>>
>> Hi,
>> thanks
>> I changed slightly the code to be reproducible from everyone . I have  tried 
>> ggplot
>> but I need a bit of help to tweak it a bit
>>
>> So you can run the following in your computer
>>
>>   
>>testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(1:5,1:5))
>>
>>   p<-ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
>>ylab("Threshold") +    geom_raster()
>>
>>
>>   p
>>
>>
>> What I want to improve is
>> a: make the colorbar so only two specific colors lets say black and white 
>> and only two values 0 and 1 and somewhere the string as title of the color 
>> bar "text" to appear.
>>
>> I have tried something like
>> p+   scale_color_gradient(low="red",high="blue")
>> Fehler in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
>>
>>
>> ggplot(melt(testData), aes(Var2,Var1, fill=value,colorbin=2))+xlab("MHz") + 
>> ylab("Threshold") +    geom_raster()
>> but this did not affect colorbar entries.
>>
>>
>> b. reduce/remove the grayish border that appears between the legend and the 
>> image plot
>>
>> Could you please help me with these two?
>>
>> Regards
>> Alex
>>
>>
>>
>> 
>> From: John Kane 

>> Sent: Thursday, February 14, 2013 4:35 PM
>> Subject: RE: [R] Plot a Matrix as an Image with ggplot
>>
>> The R-help list is rather picky about what attached. None of your 
>> attachments arrived.
>>
>> The str() info is useful but please supply some sample data
>>
>> The easiest way to supply data  is to use the dput() function.  Example with 
>> your file named "testfile":
>> dput(testfile)
>>
>> Then copy the output and paste into your email.  For large data sets, you 
>> can just supply a representative sample.  Usually,
>> dput(head(testfile, 100)) will be sufficient.
>>
>> How are you writing the code/or what format is the original email. Your code 
>> in the body of the text is badly messed up -- you probably need to post only 
>> in text. HTML etc is automatically dropped.
>>
>>
>>
>>
>> John Kane
>> Kingston ON Canada
>>
>>
>>> -Original Message-

>>> Sent: Thu, 14 Feb 2013 07:15:05 -0800 (PST)
>>> To: r-help@r-project.org
>>> Subject: [R] Plot a Matrix as an Image with ggplot
>>>
>>> Dear all,
>>> I am trying to plot a matrix I have  as an image
>>>
>>> str(matrixToPlot)
>>>  num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
>>>
>>>
>>>  that contains only 0s and 1s,
>>>
>>>
>>> where the xlabel will be Labeled as
>>> str(xLabel)
>>>  num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
>>>
>>> and the yLabels will be labeled as
>>> str(yLabel)
>>>  num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
>>>
>>>
>>> I have found on the internet that I can do something like that with
>>> ggplot2.
>>> For example
>>> you can run the following
>>>
>>>
>>>
>>> library(reshape2)library(ggplot2)m
>>> =matrix(rnorm(20),5)ggplot(melt(m),aes(Var1

[R] ggplot2 customizing a plot

2013-02-20 Thread Alaios
Dear all,
I want some help improve my ggplot as following:
Make the plottable area with grid, so is easy one to see where each box refers 
to x and y values.
Add a color bar but with fixed values, that I want to specify.
How   I can do those two?

Before is some code what I have tried so far.

Regards
Alex 


DataToPlot<-matrix(data=seq(1:9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))   
    


require(reshape)
require(ggplot2)
require(raster)


 
 tdm <- melt(DataToPlot)  



p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
    labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
    geom_raster() +
    scale_fill_discrete()

[[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] ggplot2 customizing a plot

2013-02-21 Thread Alaios
Hello Ista,
I would like to thank you for your reply!

Your code is indeed an improvement.

This is my code now and there are two things still missing.

DataToPlot<-matrix(data=runif(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
require(reshape)
require(ggplot2)
require(raster)


cols<-colours()
cols<-cols[1:(nrow(DataToPlot)*ncol(DataToPlot))]
tdm<-melt(DataToPlot)
p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
geom_raster(alpha=.5) +
scale_fill_manual(values=cols,breaks=c("1","0.9","0.8","0.7","0.6","0.5","0.4","0.3","0.2","0.1","0"))

My values go from 0 to 1 (might go slightly over the limits) and I want to 
specify one color for the following ranges, 1, 0.9,0.8,.,0 .  That means 
that values between the intervals will be "categorized" based on their closest 
match.
What I also tried is to create a gray scale pallete as this is printer friendly 
so the values from 0.9 to 0.1 get a greyish tone but I failed to do that with 
colours.

Could you please help me have both
a. A fixed scale where values are categorized there
and 
b. a greyish pallete for the categories?

I would like to thank you in advance for your reply

Regards
Alex





 From: Ista Zahn 

Cc: R help  
Sent: Wednesday, February 20, 2013 4:54 PM
Subject: Re: [R] ggplot2 customizing a plot

Hi,


> Dear all,
> I want some help improve my ggplot as following:
> Make the plottable area with grid, so is easy one to see where each box 
> refers to x and y values.

I don't think you can easily move the grid to the front, but you can
make the tiles transparent so the grid can be seen through them by
setting the alpha < 1.

> Add a color bar but with fixed values, that I want to specify.

use scale_fill_manual

> How   I can do those two?

p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
  geom_raster(alpha=.5) +
  scale_fill_manual(values=c("red", "blue", "green", "purple",
"orange", "pink", "tan", "violet", "yellow"))


Best,
Ista


>
> Before is some code what I have tried so far.
>
> Regards
> Alex
>
>
> DataToPlot<-matrix(data=seq(1:9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
>
>
> require(reshape)
> require(ggplot2)
> require(raster)
>
>  tdm <- melt(DataToPlot)
>
>
>
> p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
>             labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
>             geom_raster() +
>             scale_fill_discrete()
>
>         [[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.
>
[[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] ggplot2 customizing a plot

2013-02-21 Thread Alaios
Let me try to explain this then.

I have numbers like 

DataToPlot
  4 5 6
1 0.4454995 0.4462009 0.4286807
2 0.3761550 0.5423205 0.6500785
3 0.3779496 0.4671437 0.1799601


and I want to have a color legend with each color that is mapped to the 
following printed values

"1","0.9","0.8","0.7","0.6","0.5","0.4","0.3","0.2","0.1","0"

For making life easier I have rounded up my number to one digit so

  
matrixToPlot<-matrix(data=round(matrixToPlot,digits=1),nrow=nrow(matrixToPlot),ncol=ncol(matrixToPlot),dimnames=list(yLabel,
 xLabel))
matrixToPlot
    1   2   3
1 0.4 0.4 0.4
2 0.4 0.5 0.7
3 0.4 0.5 0.2


that indeed helps and makes the legend bar print the right values BUT there are 
not all the ranges printed there. So for the given example data set only the 
0.2, 0.3,0.4,0.5,0.6,0.7 are printed with the 0,0.1,0.8,0.9,1 missing.
Also I need some help to specify specific color to each of the given 
categories/ranges in the colorbar

my code now looks like


library(reshape2)
    library(ggplot2)
    
matrixToPlot<-matrix(data=runif(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
    
matrixToPlot<-matrix(data=round(matrixToPlot,digits=1),nrow=nrow(matrixToPlot),ncol=ncol(matrixToPlot),dimnames=list(seq(1:3),
 seq(4:6)))
    tdm <- melt(matrixToPlot)
    cols<-colours()
    cols<-cols[1:(nrow(matrixToPlot)*ncol(matrixToPlot))]
    p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
  geom_raster(alpha=.5) +
  scale_fill_discrete(h.start=1) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 



Regards
Alex





 From: Ista Zahn 

Cc: R help  
Sent: Thursday, February 21, 2013 2:15 PM
Subject: Re: [R] ggplot2 customizing a plot

Hi,


> Hello Ista,
[[elided Yahoo spam]]
>
> Your code is indeed an improvement.
>
> This is my code now and there are two things still missing.
>
> DataToPlot<-matrix(data=runif(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
> require(reshape)
> require(ggplot2)
> require(raster)
>
>
> cols<-colours()
> cols<-cols[1:(nrow(DataToPlot)*ncol(DataToPlot))]
> tdm<-melt(DataToPlot)
>
> p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
> labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
> geom_raster(alpha=.5) +
> scale_fill_manual(values=cols,breaks=c("1","0.9","0.8","0.7","0.6","0.5","0.4","0.3","0.2","0.1","0"))

value looks like numbers, why are you converting it to a factor?

why this is how I found I should solve the problem..

>
> My values go from 0 to 1 (might go slightly over the limits) and I want to
> specify one color for the following ranges, 1, 0.9,0.8,.,0 .  That means
> that values between the intervals will be "categorized" based on their
> closest match.

I don't really understand this.



> What I also tried is to create a gray scale pallete as this is printer
> friendly so the values from 0.9 to 0.1 get a greyish tone but I failed to do
> that with colours.

How about

ggplot(tdm, aes(x = Var2, y = Var1, fill = value)) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
  geom_raster(alpha=.5) +
  scale_fill_gradient(low="gray90", high="black") +
  theme_bw()

>
> Could you please help me have both
> a. A fixed scale where values are categorized there
> and

Value is numeric, and trying to treat it like a category is only going
to make things difficult.

> b. a greyish pallete for the categories?

Use scale_fill_gradient with different shades of gray as the low and
high values, as shown above.

Best,
Ista

>
> I would like to thank you in advance for your reply
>
> Regards
> Alex
>
>
> 
> From: Ista Zahn 

> Cc: R help 
> Sent: Wednesday, February 20, 2013 4:54 PM
> Subject: Re: [R] ggplot2 customizing a plot
>
> Hi,
>

>> Dear all,
>> I want some help improve my ggplot as following:
>> Make the plottable area with grid, so is easy one to see where each box
>> refers to x and y values.
>
> I don't think you can easily move the grid to the front, but you can
> make the tiles transparent so the grid can be seen through them by
> setting the alpha < 1.
>
>> Add a color bar but with fixed values, that I want to specify.
>
> use scale_fill_manual
>
>> How  I can do those two?
>
> p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
>   labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
>   geom_raster(alpha=.5) +
>   scale_fill_manual(values=c("red", "blue", "green", "purple",
> "orange", "pink", "tan", "violet", "yellow"))
>
>
> Best,
> Ista
>
>
>>
>> Before is some code what I have tried so far.
>>
>> Regards
>> Alex
>>
>>
>> DataToPlot<-matrix(data=seq(1:9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
>>
>>
>> require(reshape)
>> require(ggplot2)
>> require(raster)
>>
>>  tdm <- melt(DataToPlot)
>>
>>
>>
>> p<- ggplot(tdm, aes(x = Var2, y = Va

[R] ggplot2 Increase font size

2013-02-25 Thread Alaios
Dear all,
I am using the code as below
  tdm <- melt(matrixToPlot)
   p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
  labs(x = "Mz", y = "T", fill = "D") +
  geom_raster(alpha=1) +
  scale_fill_discrete(h.start=1) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0))

to plot an two dimensional image .

I would like to ask your help to replace the gray border with white color and 
increase the font size of x and y axis as wells as the legend of the color bar. 
Could you please give me the function names to use?

Regards
Alex
[[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] parallel execution in R

2013-02-26 Thread Alaios
Dear all,
I have a piece of code that  I want to run in parallel (I am working in system 
of 16 cores)


foreach (i=(seq(-93,-73,length.out=21))) %dopar% 
 {
  threshold<-i
 
 print(i)
 do_analysis1(i,path)
 do_analysis2(i,path)
           do_something_else_analysis1(i,path)
           something_else_now(i,path)
 }


as you can see I have already tried to make this run in parallel, meaning for 
every  i   value each of the 16 processor shoule take a block of the body such 
as:

    threshold<-i
 
 print(i)
 do_analysis1(i,path)
 do_analysis2(i,path)
           do_something_else_analysis1(i,path)
           something_else_now(i,,path)
 



and execute it . Unfortunately this does not work and oonly one processor looks 
utilized.

Alternatively, mclapply have worked well in the past, but in this case I am not 
sure how to convert the serial execution of the body of the loop to a list that 
would be compatible with the mclapply. 

I would like to thank you in advance for your help

Regards
Alex

[[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] ggplot2 Increase font size

2013-02-26 Thread Alaios
Hi,
I am not quite sure what you meanΙ. I give again reproducible code:



require(ggplot2)
require(reshape)

DataToPlot<-matrix(data=rnorm(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
tdm<-melt(DataToPlot)
p<- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
                  labs(x = "MHz", y = "Threshold", fill = 
"Duty Cycle") +
                  geom_raster(alpha=1) +
                  
scale_fill_discrete(h.start=1,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1))
 +
                  scale_x_continuous(expand = c(0, 0)) +
                  scale_y_continuous(expand = c(0, 0))







DataToPlot in my case contains something like that:

DataToPlot
           4          5          6
1 -0.4135124  0.4643110 -0.7530622
2  0.8827643 -0.1702428  0.4607671
3  0.7942167 -1.2450487 -0.9380290


what I would like to have is to have one specific color for each of the 
following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)

so for example the -0.4 would be categorized under the 0 category 

the 0.46 would be categorized under the 0.5 category
the -0.75 would be categorized under the 0 category
the 0.88 would be categorized under the 0.9 category


right now the code I gave prints no color bar. If I change it like that.
p<- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
                  labs(x = "MHz", y = "Threshold", fill = 
"Duty Cycle") +
                  geom_raster(alpha=1) +
                 
 
scale_fill_discrete(h.start=1)
 +
                  scale_x_continuous(expand = c(0, 0)) +
                  scale_y_continuous(expand = c(0, 0))


colorbar comes back but as you will see the defined values is not how I want to 
categorize my data.

Could you please help me find what I do not understand here?

I would like to thank you in advance for your reply

Regards
Alex




 From: Ista Zahn 

Cc: R help  
Sent: Monday, February 25, 2013 3:54 PM
Subject: Re: [R] ggplot2 Increase font size

Hi Alex,

See ?theme

Best,
Ista


>
> Dear all,
> I am using the code as below
>   tdm <- melt(matrixToPlot)
>    p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
>                   labs(x = "Mz", y = "T", fill = "D") +
>                   geom_raster(alpha=1) +
>                   scale_fill_discrete(h.start=1) +
>                   scale_x_continuous(expand = c(0, 0)) +
>                   scale_y_continuous(expand = c(0, 0))
>
> to plot an two dimensional image .
>
> I would like to ask your help to replace the gray border with white color
> and increase the font size of x and y axis as wells as the legend of the
> color bar. Could you please give me the function names to use?
>
> Regards
> Alex
>         [[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.
>
[[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] lm and Formula tutorial

2013-03-05 Thread Alaios
Dear all,
I was reading last night the lm and the Formula manual page, and 'I have to 
admit that I had tough time to understand their syntax. Is there a simpler 
guide for the dummies like me to start with?

I would like to thank you in advance for your help

Regards
Alex
[[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] All unique combinations

2013-03-21 Thread Alaios
Dear all,
I would like to have all unique combinations in the following matrix

TimeIndex<- rbind (c(1,"Week_of_21_07-29_03"), 
          c(2,"Thursday_21_03"),
          c(3,"Friday_22_03"),
          c(4,"Saturday_23_03"),
          c(5,"Sunday_24_03"),
          c(6,"Monday_25_03"),
          c(7,"Tuesday_26_03"),
          c(8,"Wednesday_27_03"),
          c(9,"Thursday_28_03"),
          c(10,"Friday_ 29_03"))


As  have a plotting code that takes two input arguments 

plot_two_time_frames(time1,LabelTime1,time2,LabelTime2)
these inputs are
time1: integer from TimeIndex.  TimeIndex[i,1]
LabelTime1: Labels from  TimeIndex[i,2]

time2: integer from TimeIndex, TimeIndex[i,1]
LabelTime2: Labels from  TimeIndex[i,2]


the times 1 and time 2 should be unique combinations and never the same number. 
I understand that my explanation was not the best possible. But I would like to 
thank you in advance for your support

Regards
Alex
[[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] plot Raster

2013-03-25 Thread Alaios
Dear all,
I am trying to plot an image so I am trying this through raster layer.

You can copy paste the following

require('raster')
Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
rasterData<-raster(Data)
lengthOut<-5
xAxisFrequencies<-seq(800,900,length.out=lengthOut)
plot(rasterData, ylab="",xaxt="n",yaxt="n")
axis(1, at=seq(0,1,length.out=lengthOut), xAxisFrequencies, col.axis = "blue")



What I want is to add a customized x label, but the last line I gave above
axis(1,at.) does not work. 

It would be also nice to add a bit of legend also under the color bar to 
explain there what are the values.

Could you please help me with those two ?

Regards
Alex

[[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] Plot Matrix with Data

2013-03-25 Thread Alaios
Hi ,
I would like to use ggplot2 to plot a matrix as an image.

You can copy paste the following


Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)

lengthOut<-5



Lengths<- 15
library(reshape2)
library(ggplot2)
tdm <- melt(Data)





ggplot(tdm, aes(x = Var2, y = Var1, fill = 
factor(value)),levels=seq(0,1,by=0.1)) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
  geom_raster(alpha=1) +
  
scale_fill_discrete(h.start=1,breaks=c(20,30,40,50,60,70,80,90),labels=c(20,30,40,50,60,70,80,90),fill="red")
 +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0))






# End of code part



What I wanted to do is to print the values 

below 20, with an x color
between 20-30, with a y clor
between 30-40, with a z color
and so on

I would not care now for the color palette.
Any would do.
Could you please help me with that?

Regards
A

[[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] Plot Matrix with Data

2013-03-26 Thread Alaios
Hi,
Thanks for the answer.
It looks like that the mutate what I was missing so long..

That's my current attempt

Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
Lengths<- 15
library(reshape2)
library(ggplot2)
require('plyr')
tdm <- melt(Data)
tdm <- mutate(tdm, col = cut(value, seq(15, 90, by=5), labels = seq(20, 90, 
by=5)) )
test<-colorRampPalette(c("orange", "red"),space="Lab",interpolate="linear")
ggplot(tdm, aes(x = Var1, y = Var2, fill = col)) +
  geom_raster() +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle")


Two things.
a. I have tried to make a color pallete that goes from orange through all the 
orangish and redish hues to the red but as you can see that failed.
b. One think is that the colors visible in the legend in the right part are not 
always visible. If for example there is a 20 value the 20 will appear and if 
there is not but there is a 25 the bar will start from the 25 onwards.

I would like to thank everyone for their on going support

Regards
Alex



 From: Dennis Murphy 

Sent: Monday, March 25, 2013 9:17 PM
Subject: Re: [R] Plot Matrix with Data

Hi Alex:

Here are a couple of raw examples, one with a 'discretized' color
gradient and another with ordered factor levels in groups of length
10. Starting with tdm,

library(plyr)
library(ggplot2)
tdm <- mutate(tdm, col = cut(value, seq(0, 140, by = 10),
                              labels = seq(10, 140, by = 10)) )
## or equivalently,
# tdm$col <- cut(col$value, seq(0, 140, by = 10),
#                      labels = seq(10, 140, by = 10)) )

# The numeric factor levels are 1 - 14, so if we convert col to numeric,
# should multiply the values by 10. This plot uses a continuous
# color gradient whose midpoint is near the median value.
ggplot(tdm, aes(x = Var1, y = Var2, fill = 10 * as.numeric(col))) +
       geom_raster() +
       scale_x_continuous(expand = c(0, 0)) +
       scale_y_continuous(expand = c(0, 0)) +
       scale_fill_gradient2(low = "green", mid = "orange",
                            high = "yellow", midpoint = 85) +
       labs(x = "MHz", y = "Threshold", fill = "Duty Cycle")

# This one uses col as a factor. The labels are the correct
# upper limits of each value bin. Obviously you want to use
# a smarter mechanism for assigning colors than the
# default. The colorspace package or the colorRampPalette()
# function might be useful here.
ggplot(tdm, aes(x = Var1, y = Var2, fill = col)) +
  geom_raster() +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  labs(x = "MHz", y = "Threshold", fill = "Duty Cycle")

The values on the x-y axes are the row and column numbers of the
reshaped matrix. You may need to map them to values of the MHz and
Threshold values; I doubt that [0, 1] is the range of each variable
(as you have in another post using base graphics).

Dennis


> Hi ,
> I would like to use ggplot2 to plot a matrix as an image.
>
> You can copy paste the following
>
>
> Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
>
> lengthOut<-5
>
>
>
> Lengths<- 15
> library(reshape2)
> library(ggplot2)
> tdm <- melt(Data)
>
>
>
>
>
> ggplot(tdm, aes(x = Var2, y = Var1, fill = 
> factor(value)),levels=seq(0,1,by=0.1)) +
>                   labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
>                   geom_raster(alpha=1) +
>                   
>scale_fill_discrete(h.start=1,breaks=c(20,30,40,50,60,70,80,90),labels=c(20,30,40,50,60,70,80,90),fill="red")
> +
>                   scale_x_continuous(expand = c(0, 0)) +
>                   scale_y_continuous(expand = c(0, 0))
>
>
>
>
>
>
> # End of code part
>
>
>
> What I wanted to do is to print the values
>
> below 20, with an x color
> between 20-30, with a y clor
> between 30-40, with a z color
> and so on
>
> I would not care now for the color palette.
> Any would do.
> Could you please help me with that?
>
> Regards
> A
>
>         [[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.
>
[[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] Increase font size in plots

2013-03-26 Thread Alaios
Hi
I am using violin plots (type of boxplots) and  I am trying to increase the 
font size in the plots.

It looks like that the violin plots do not work as "normal" plots as the cex 
parameters are ignored.

You can have a loot at the code below




require('vioplot')
data1<-rnorm(100)
data2<-rnorm(10)
data3<-rnorm(1000)
vioplot(data1,data2,data3,cex.lab=2,cex.axis=2)




Regards
Alex
[[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] Plot Matrix with Data

2013-03-26 Thread Alaios
Hi,
it was very kind of you to help me again.

Your code works, and the reason I was using the limits as that is that my 
dataset is slightly different than the one I used for showing the problem here.
More specifically this is my dataset

Browse[1]> str(keep)
 num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...
Browse[1]> (density(keep))

Call:
    density.default(x = keep)

Data: keep (525565085 obs.);    Bandwidth 'bw' = 0.1695

   x y    
 Min.   :-106.94   Min.   :0.000  
 1st Qu.: -87.13   1st Qu.:0.0003593  
 Median : -67.31   Median :0.0050385  
 Mean   : -67.31   Mean   :0.0126038  
 3rd Qu.: -47.49   3rd Qu.:0.0084189  
 Max.   : -27.67   Max.   :0.1792683  



and as you can see is rather large... that makes it a marathon to print it. 
Would it be possible to average some of the arrows in a column by column basis 
so to turn the

str(keep)
 num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...

to something like

num [1:1000, 1:3415] . How can I do that efficiently in R?

I would like to thank everyone in advance.

Regards
Alex







 From: Dennis Murphy 

Sent: Tuesday, March 26, 2013 10:43 AM
Subject: Re: [R] Plot Matrix with Data

Hi:

I don't understand why you're truncating the duty cycle at 90 when the
data range from 15 to 150 - the effect of doing that is the set of
grey squares in the heatmap corresponding to missing values.

The reason your color scale didn't work is because you never used it
in the ggplot() call, but I think that it would have been difficult to
incorporate it anyway because ggplot2 has its own conventions. It
appears that what you want is ggplot2::scale_fill_continuous().

I chucked the color factor and tried the following instead. You can
edit it however you want, and you can extend the length/width of the
color bar - see the help page of guide_colourbar(), in particular the
barheight argument.
http://docs.ggplot2.org/current/guide_colourbar.html

My shot at your graphic:

ggplot(tdm, aes(x = Var1, y = Var2, fill = value)) +
   geom_raster() +
   scale_x_continuous(expand = c(0, 0)) +
   scale_y_continuous(expand = c(0, 0)) +
   scale_fill_continuous(limits = c(15, 150),
                         breaks = seq(15, 150, by = 15),
                         low = "orange", high = "red",
                         guide = guide_colourbar(nbin = 28)) +
   labs(x = "MHz", y = "Threshold", fill = "Duty Cycle")

This color bar has 28 bins, 5 units apart, but the labels are 15 apart
since otherwise they overwrite each other. You can reduce the crowding
by increasing the height of the color bar as indicated earlier. This
appears to be closer to your intent with a lot less bother.

Dennis


> Hi,
> Thanks for the answer.
> It looks like that the mutate what I was missing so long..
>
> That's my current attempt
>
> Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
>
> Lengths<- 15
> library(reshape2)
> library(ggplot2)
> require('plyr')
> tdm <- melt(Data)
> tdm <- mutate(tdm, col = cut(value, seq(15, 90, by=5), labels = seq(20, 90,
> by=5)) )
> test<-colorRampPalette(c("orange", "red"),space="Lab",interpolate="linear")
>
> ggplot(tdm, aes(x = Var1, y = Var2, fill = col)) +
>   geom_raster() +
>   scale_x_continuous(expand = c(0, 0)) +
>   scale_y_continuous(expand = c(0, 0)) +
>   labs(x = "MHz", y = "Threshold", fill = "Duty Cycle")
>
>
> Two things.
> a. I have tried to make a color pallete that goes from orange through all
> the orangish and redish hues to the red but as you can see that failed.
> b. One think is that the colors visible in the legend in the right part are
> not always visible. If for example there is a 20 value the 20 will appear
> and if there is not but there is a 25 the bar will start from the 25
> onwards.
>
> I would like to thank everyone for their on going support
>
> Regards
> Alex
> 
> From: Dennis Murphy 

> Sent: Monday, March 25, 2013 9:17 PM
> Subject: Re: [R] Plot Matrix with Data
>
> Hi Alex:
>
> Here are a couple of raw examples, one with a 'discretized' color
> gradient and another with ordered factor levels in groups of length
> 10. Starting with tdm,
>
> library(plyr)
> library(ggplot2)
> tdm <- mutate(tdm, col = cut(value, seq(0, 140, by = 10),
>                               labels = seq(10, 140, by = 10)) )
> ## or equivalently,
> # tdm$col <- cut(col$value, seq(0, 140, by = 10),
> #                      labels = seq(10, 140, by = 10)) )
>
> # The numeric factor levels are 1 - 14, so if we convert col to numeric,
> # should multiply the values by 10. This plot uses a continuous
> # color gradient whose midpoint is near the median value.
> ggplot(tdm, aes(x = Var1, y = Var2, fill = 10 * as.numeric(col))) +
>       geom_raster() +
>       scale_x_continuous(expand = c(0, 0)) +
>       scale_y_continuous(expand = c(0, 0)) +
>       scale_fill_gradient2(low = "green", mid = "orange",
>                             high = "yellow", midpoint =

[R] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Alaios
Dear all,
1) I have a very large matrix of 
str(keep) 
 num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... 
that  I would like to reduce its size to something like

str(keep) 
 num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...  
or anything similar in size as this is a matrix that needs plotting (so is ok 
if it is 1000 row, 995, or 1123)

I think what I need here is a way of selecting multiple rows and averaging per 
column (notice that the column number should stay the same)

b. I would like to be able to convert strings that are function names to real 
function calls. For example I have something like

LogFunction<- function(){}
FunctionIndex<- rbind (c(1,"LogFunction"),
           c(2,"TakeFunction")
          )
print(sprintf('Using the function %s',FunctionIndex[1,1]))
# call the FunctionIndex[1,1] somehow 



I would like to thank you in advance for your help

Regards
Alex

[[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] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Alaios
see inline




 From: PIKAL Petr 

Sent: Wednesday, March 27, 2013 11:24 AM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string

Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Alaios
> Sent: Wednesday, March 27, 2013 9:13 AM
> To: R help
> Subject: [R] Averaging Out many rows from a column AND funtion to
> string
> 
> Dear all,
> 1) I have a very large matrix of
> str(keep)
>  num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...
> that  I would like to reduce its size to something like
> 
> str(keep)
>  num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... or anything
> similar in size as this is a matrix that needs plotting (so is ok if it
> is 1000 row, 995, or 1123)
> 
> I think what I need here is a way of selecting multiple rows and
> averaging per column (notice that the column number should stay the
> same)

Make an index variable and aggregate values according it

Something like
idx<-cut(1:153899, 153)
keep.ag<-aggregate(keep, list(idx), mean)

1) Thanks that returned a data frame.. How I can have a matrix at the end?
2) I want to have a string that can be used also for calling a function with 
the same name. Think of using "mean" to call mean. I need to have R interpret 
the string in different ways.

Regards
Alex

> 
> b. I would like to be able to convert strings that are function names
> to real function calls. For example I have something like
> 
> LogFunction<- function(){}
> FunctionIndex<- rbind (c(1,"LogFunction"),
>            c(2,"TakeFunction")
>           )
> print(sprintf('Using the function %s',FunctionIndex[1,1])) # call the
> FunctionIndex[1,1] somehow

I am not sure if I understand correctly. 

Is this what you want?
myf <-function(fun="mean", arg) eval(call(fun, arg))

Regards
Petr

> 
> 
> 
> I would like to thank you in advance for your help
> 
> Regards
> Alex
> 
>     [[alternative HTML version deleted]]
[[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] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Alaios
see inline





 From: PIKAL Petr 

Sent: Wednesday, March 27, 2013 1:50 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string



Hi
 

Sent: Wednesday, March 27, 2013 11:46 AM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
see inline
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 11:24 AM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string

Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Alaios
> Sent: Wednesday, March 27, 2013 9:13 AM
> To: R help
> Subject: [R] Averaging Out many rows from a column AND funtion to
> string
> 
> Dear all,
> 1) I have a very large matrix of
> str(keep)
>  num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...
> that  I would like to reduce its size to something like
> 
> str(keep)
>  num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... or anything
> similar in size as this is a matrix that needs plotting (so is ok if it
> is 1000 row, 995, or 1123)
> 
> I think what I need here is a way of selecting multiple rows and
> averaging per column (notice that the column number should stay the
> same)

Make an index variable and aggregate values according it

Something like
idx<-cut(1:153899, 153)
keep.ag<-aggregate(keep, list(idx), mean)

1) Thanks that returned a data frame.. How I can have a matrix at the end?


use as.matrix(data.frame) on numeric part

a bit of my code that you can re run. I convert a 30,30 matrix to a 10,30.  
but it looks at the end that I do not get the Data part of the data.fram 
correctly: 

Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
idx<-cut(1:30, 10)
keep.ag<-aggregate(Data, list(idx), mean)
str(as.matrix(keep.ag) ) # it does not look like integers









2) I want to have a string that can be used also for calling a function with 
the same name. Think of using "mean" to call mean. I need to have R interpret 
the string in different ways.


To call „mean“ of what? I am sure I do not understand what is your 
intention.
LogFunction<- function(){}
FunctionIndex<- rbind (c(1,"LogFunction"),
               c(2,"TakeFunction"))
print(sprintf('Using the function %s',FunctionIndex[1,1]))
This does not contain much clue.
Regards
Petr
PS. Do not use HTML mail messages. 
Regards
Alex

> 
> b. I would like to be able to convert strings that are function names
> to real function calls. For example I have something like
> 
> LogFunction<- function(){}
> FunctionIndex<- rbind (c(1,"LogFunction"),
>                c(2,"TakeFunction")
>               )
> print(sprintf('Using the function %s',FunctionIndex[1,1])) # call the
> FunctionIndex[1,1] somehow

I am not sure if I understand correctly. 

Is this what you want?
myf <-function(fun="mean", arg) eval(call(fun, arg))

Regards
Petr

> 
> 
> 
> I would like to thank you in advance for your help
> 
> Regards
> Alex
> 
>     [[alternative HTML version deleted]]
[[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] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Alaios
I have fixed it like that:


keep<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
ShrinkTo<-500
idx<-cut(1:nrow(keep), ShrinkTo)
keep.ag<-aggregate(keep, list(idx), mean)
PlotMe<-data.matrix(keep.ag[2:ShrinkTo])

The only problem is that takes ages to finish. Would it be possible to 
convert it to something like lapply?

Regards
Alex





 From: PIKAL Petr 

Sent: Wednesday, March 27, 2013 4:02 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string



Hi
 
> str(as.matrix(keep.ag[,-1]) )  # does look like numeric
num [1:10, 1:30] 75.1 93 79 81.7 76.3 ...
- attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:30] "V1" "V2" "V3" "V4" ...
 
Please read and follow what was recommended.
 
quote
 
use as.matrix(data.frame) on numeric part
                                        
                  ^^^
 
aggregate produces data frame with its first column being your idx variable, 
which is factor. Trying to convert it whole to matrix results in character 
matrix. You need to exclude first column from conversion
 
And please can you explain how mean(rnorm(whatever)) shall be integer?
 
Regards
Petr
 

Sent: Wednesday, March 27, 2013 3:01 PM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
see inline
 
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 1:50 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string


Hi
 

Sent: Wednesday, March 27, 2013 11:46 AM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
see inline
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 11:24 AM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string

Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Alaios
> Sent: Wednesday, March 27, 2013 9:13 AM
> To: R help
> Subject: [R] Averaging Out many rows from a column AND funtion to
> string
> 
> Dear all,
> 1) I have a very large matrix of
> str(keep)
>  num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...
> that  I would like to reduce its size to something like
> 
> str(keep)
>  num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... or anything
> similar in size as this is a matrix that needs plotting (so is ok if it
> is 1000 row, 995, or 1123)
> 
> I think what I need here is a way of selecting multiple rows and
> averaging per column (notice that the column number should stay the
> same)

Make an index variable and aggregate values according it

Something like
idx<-cut(1:153899, 153)
keep.ag<-aggregate(keep, list(idx), mean)

1) Thanks that returned a data frame.. How I can have a matrix at the end?
use as.matrix(data.frame) on numeric part
 
a bit of my code that you can re run. I convert a 30,30 matrix to a 10,30.  
but it looks at the end that I do not get the Data part of the data.fram 
correctly: 
Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
idx<-cut(1:30, 10)
keep.ag<-aggregate(Data, list(idx), mean)
str(as.matrix(keep.ag) ) # it does not look like integers
 
 
 
 
 
 
 
2) I want to have a string that can be used also for calling a function with 
the same name. Think of using "mean" to call mean. I need to have R interpret 
the string in different ways.
To call „mean“ of what? I am sure I do not understand what is your 
intention.
LogFunction<- function(){}
FunctionIndex<- rbind (c(1,"LogFunction"),
               c(2,"TakeFunction"))
print(sprintf('Using the function %s',FunctionIndex[1,1]))
This does not contain much clue.
Regards
Petr
PS. Do not use HTML mail messages. 
Regards
Alex

> 
> b. I would like to be able to convert strings that are function names
> to real function calls. For example I have something like
> 
> LogFunction<- function(){}
> FunctionIndex<- rbind (c(1,"LogFunction"),
>                c(2,"TakeFunction")
>               )
> print(sprintf('Using the function %s',FunctionIndex[1,1])) # call the
> FunctionIndex[1,1] somehow

I am not sure if I understand correctly. 

Is this what you want?
myf <-function(fun="mean", arg) eval(call(fun, arg))

Regards
Petr

> 
> 
> 
> I would like to thank you in advance for your help
> 
> Regards
> Alex
> 
>     [[alternative HTML version deleted]]
[[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] Controlling Raster plots

2013-03-27 Thread Alaios
Hi,
I have a few raster layers and I would like to customized their x and y axis.

I have tried already something like:


require('raster')
keep<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
xlab<-seq(100e6,200e6,length.out=5)
test<-raster(keep)
plot(test,ylab="",xaxt="n",yaxt="n")
axis(1, at=seq(0,1,length.out=5), xlab)

that normally would work in any other plot function.

Could you please help me add the xaxis ?

I would like to thank you in advance for your reply

Regards
Alex

[[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] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Alaios
Well my true matrix is 

of


num [1:153899, 1:3415]

that I want to convert to something like

num [1:1000, 1:3415] (keeping column number the same).

I only give subsets here to allow others to run the code at their computer

Thanks a lot

Regards
Alex




 From: PIKAL Petr 

Sent: Wednesday, March 27, 2013 4:45 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string



Hi
 
> system.time({
+ keep<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
+ ShrinkTo<-500
+ idx<-cut(1:nrow(keep), ShrinkTo)
+ keep.ag<-aggregate(keep, list(idx), mean)
+ PlotMe<-as.matrix(keep.ag[,-1])
+ })
   user  system elapsed 
  29.23    0.14   29.37 
>  
 
It takes 30 seconds when using 30 rows. It is not enough time to get a cup 
of tee, which I do not consider ages. Maybe split lapply approach or 
data.matrix or  **ply could be quicker but I do not consider worth spending 
hours to elaborate some solution which will spare 20 sec computing time.
 
Regards
Petr 
 

Sent: Wednesday, March 27, 2013 4:12 PM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
I have fixed it like that:


keep<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
ShrinkTo<-500
idx<-cut(1:nrow(keep), ShrinkTo)
keep.ag<-aggregate(keep, list(idx), mean)
PlotMe<-data.matrix(keep.ag[2:ShrinkTo])

The only problem is that takes ages to finish. Would it be possible to 
convert it to something like lapply?

Regards
Alex
 
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 4:02 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string


Hi
 
> str(as.matrix(keep.ag[,-1]) )  # does look like numeric
num [1:10, 1:30] 75.1 93 79 81.7 76.3 ...
- attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:30] "V1" "V2" "V3" "V4" ...
 
Please read and follow what was recommended.
 
quote
 
use as.matrix(data.frame) on numeric part
                                        
                  ^^^
 
aggregate produces data frame with its first column being your idx variable, 
which is factor. Trying to convert it whole to matrix results in character 
matrix. You need to exclude first column from conversion
 
And please can you explain how mean(rnorm(whatever)) shall be integer?
 
Regards
Petr
 

Sent: Wednesday, March 27, 2013 3:01 PM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
see inline
 
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 1:50 PM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string
 
Hi
 

Sent: Wednesday, March 27, 2013 11:46 AM
To: PIKAL Petr; R help
Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
 
see inline
 



From:PIKAL Petr 

Sent: Wednesday, March 27, 2013 11:24 AM
Subject: RE: [R] Averaging Out many rows from a column AND funtion to string

Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Alaios
> Sent: Wednesday, March 27, 2013 9:13 AM
> To: R help
> Subject: [R] Averaging Out many rows from a column AND funtion to
> string
> 
> Dear all,
> 1) I have a very large matrix of
> str(keep)
>  num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ...
> that  I would like to reduce its size to something like
> 
> str(keep)
>  num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... or anything
> similar in size as this is a matrix that needs plotting (so is ok if it
> is 1000 row, 995, or 1123)
> 
> I think what I need here is a way of selecting multiple rows and
> averaging per column (notice that the column number should stay the
> same)

Make an index variable and aggregate values according it

Something like
idx<-cut(1:153899, 153)
keep.ag<-aggregate(keep, list(idx), mean)

1) Thanks that returned a data frame.. How I can have a matrix at the end?
use as.matrix(data.frame) on numeric part
 
a bit of my code that you can re run. I convert a 30,30 matrix to a 10,30.  
but it looks at the end that I do not get the Data part of the data.fram 
correctly: 
Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
idx<-cut(1:30, 10)
keep.ag<-aggregate(Data, list(idx), mean)
str(as.matrix(keep.ag) ) # it does not look like integers
 
 
 
 
 
 
 
2) I want to have a string that can be used also for calling a function with 
the same name. Think of using "mean" to call mean. I need to have R interpret 
the string in different ways.
To call „mean“ of what? I am sure I do not understand what is your 
intention.
LogFunction<- function(){}
FunctionIndex<

[R] Sort or Permutate

2012-09-11 Thread Alaios
Dear all,
I am having a struct that contains on the first column file names and on the 
second column a number which is a "rating" of the file on first column

A small subset looks like that

small
 
[,1]
 
[1,] "/storage/storage0/59Off.Rtable"
[2,] "/storage/storage0/5912On.Rtable" 
[3,] "/storage/storage0/5912314ff.Rtable"
 [,2]   
[1,] "0.220386301811093"
[2,] "0.405237035258638"
[3,] "0.288659374128626"


I want based on the values of column two to rearrange table elements by keeping 
though the row elements together.
For example if I order those in ascending order should look like




small
 
[,1]
 
[1,] "/storage/storage0/59Off.Rtable"
[2,] "/storage/storage0/5912314ff.Rtable" 
[3,] " /storage/storage0/5912On.Rtable"

 [,2]   
[1,] "0.220386301811093"
[2,] "0.288659374128626"
[3,] "0.405237035258638"

I have tried with sort, sort.list and order but I have failed .
I do not quite undestand how one can complete this task in R.
Could you please spend some time helping me?

Regards
A

[[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] Select 5 identical numbers

2014-01-20 Thread Alaios
Dear all,
I would like to select from a vector of 10 elements, 5 of those that are 
identical.
How can I do that in R? I guess one way would be to taking random numbers and 
see if that appeared again. Is though there a more straightforward approach?

Regards
Alex
[[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] Select 5 identical numbers

2014-01-20 Thread Alaios
Hi,
I want from a vector containing has like 1000 elements to select X of it 
randomly but with never selecting the same element again. Each one should be 
unique element of the vector.
Is this more precise now?

Regards
Alex




On Monday, January 20, 2014 7:54 PM, Alaios  wrote:
 
Dear all,
I would like to select from a vector of 10 elements, 5 of those that are 
identical.
How can I do that in R? I guess one way would be to taking random numbers and 
see if that appeared again. Is though there a more straightforward approach?

Regards
Alex
    [[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.
[[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] Density or Boxplot with median and mean

2014-01-22 Thread Alaios
Hi there,
I would like to be able to draw a density plot or a box plot where the median 
and the median and the mean would be visible.

If I decide a density plot I need to put two big marks one for the median and 
one for the mean, which I do not know how I can achieve to put marks in a 
density plot. For that I am using plot(density(myVector))

while on the boxplot median is already visible but mean not. To have the mean 
there I would have to add one more line on each boxplot, perhaps of different 
color but I am not sure if that is possible in R. boxplot(myVector) I am using

where myVector can be something like myVector<-seq(1,200)

I would like to thank you all in advance 
Regards
Alex
[[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] Density or Boxplot with median and mean

2014-01-22 Thread Alaios
Thanks Jim.. once again your rock





On Wednesday, January 22, 2014 9:51 AM, Jim Lemon  wrote:
 
On 01/22/2014 07:37 PM, Alaios wrote:

> Hi there,
> I would like to be able to draw a density plot or a box plot where the median 
> and the median and the mean would be visible.
>
> If I decide a density plot I need to put two big marks one for the median and 
> one for the mean, which I do not know how I can achieve to put marks in a 
> density plot. For that I am using plot(density(myVector))
>
> while on the boxplot median is already visible but mean not. To have the mean 
> there I would have to add one more line on each boxplot, perhaps of different 
> color but I am not sure if that is possible in R. boxplot(myVector) I am using
>
> where myVector can be something like myVector<-seq(1,200)
>
Hi Alex,
On a density plot you can use abline:

abline(v=mean(myVector),col="red")
abline(v=median(myVector),col="green")

I don't know of any boxplot function that will plot two measures of 
central tendency, but box.heresy in plotrix will plot any one measure 
that you like.

Jim
[[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] Which distribution to select (massive fitting)

2014-02-10 Thread Alaios
Hi all,
I have a large number of measurements from which I select a large number of 
unique vectors. For each vectors I would like to test which distribution might 
be a candidate for fitting.
It is impossible to look on each vector separately but I can inside a for loop 
test different models and based on their goodness of fit to make offline 
decisions (I will be saving goodness of fits results on a text file).

Do you know given a vector how I can get the goodness of fit for the "basic" 
distributions : "norm", "lnorm", "pois", "exp", "gamma", "nbinom",
"geom", "beta", "unif" and "logis"

Is it possible to try many of those (or at least some of the above) and try to 
get these results?

Regards
Alex
[[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] Ignore errors and proceed to next

2014-02-14 Thread Alaios
Hi all,
I have a very large number of vectors that I want first to look fast which 
distribution might be considered candidate for fitting.
I made a simple loop that checks for all vector (the code below is for one 
vector and being called for each vector separately). If a good fit is found 
this is dumped to a txt file so to allow me later on, see results

distList<-c("norm","exp","gamma","lnorm")
    for (dist in distList) {
    
        if (gofstat(fitdist(onVector,distr=dist))$kstest =="not rejected"){
        # keep it
      out<-capture.output(gofstat(fitdist(onVector,distr=distr))$ks)
      print(sprintf("Saving to file %s ",filename))
      cat(out,file=paste(filename,".txt",sep=""),sep="\n",append=TRUE)
      
        }
    }
the major problem is that these for loops return errors (sometimes for a given 
vector a specific distribution does not make sense or the vector might be zero 
or containing only many times the same element)    . The easiest would be in 
errors and warning just move to the next element of the for loop.
Something like that

for ()
{
 if error==skip to next element
 else do normal stuff
}
how I can do that in R?
Regards
Alex
[[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] Ignore errors and proceed to next

2014-02-14 Thread Alaios
Hi thanks for the answer.
I have so vast majority of vectors that some distributions will not work for 
some cases but they work for others pretty well. This is the reason I store 
only those that worked to helpe get a coarse understanding how to proceed. If 
you have a better idea let me know





On Friday, February 14, 2014 10:35 AM, Frede Aakmann Tøgersen 
 wrote:
 
Hi

See

?try
?tryCatch

So you still want to do these distribution tests even though you have been 
warned not to?

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Alaios
> Sent: 14. februar 2014 10:14
> To: R-help@r-project.org
> Subject: [R] Ignore errors and proceed to next
> 
> Hi all,
> I have a very large number of vectors that I want first to look fast which
> distribution might be considered candidate for fitting.
> I made a simple loop that checks for all vector (the code below is for one
> vector and being called for each vector separately). If a good fit is found 
> this
> is dumped to a txt file so to allow me later on, see results
> 
> distList<-c("norm","exp","gamma","lnorm")
>     for (dist in distList) {
> 
>         if (gofstat(fitdist(onVector,distr=dist))$kstest =="not rejected"){
>         # keep it
>       out<-capture.output(gofstat(fitdist(onVector,distr=distr))$ks)
>       print(sprintf("Saving to file %s ",filename))
>       cat(out,file=paste(filename,".txt",sep=""),sep="\n",append=TRUE)
> 
>         }
>     }
> the major problem is that these for loops return errors (sometimes for a
> given vector a specific distribution does not make sense or the vector might
> be zero or containing only many times the same element)    . The easiest
> would be in errors and warning just move to the next element of the for
> loop.
> Something like that
> 
> for ()
> {
>  if error==skip to next element
>  else do normal stuff
> }
> how I can do that in R?
> Regards
> Alex
>     [[alternative HTML version deleted]]
[[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] Read text file

2014-03-11 Thread Alaios
Hi all
I am trying to read some text files with the following format:

1377262633.948000    
$GPRMC,125708.00,A,5047.66107,N,00603.65528,E,0.203,247.36,230813,,,A*60
1377262633.958000    $GPVTG,247.36,T,,M,0.203,N,0.377,K,A*3B
1377262633.968000    
$GPGGA,125708.00,5047.66107,N,00603.65528,E,1,09,0.85,169.3,M,46.5,M,,*52
1377262633.978000    $GPGSA,A,3,29,21,31,25,16,05,06,13,271.78,0.85,1.57*0C
1377262633.998000    
$GPGSV,3,1,12,03,01,266,,05,16,043,39,06,21,263,43,13,07,330,43*70
1377262634.008000    
$GPGSV,3,2,12,16,37,302,45,18,03,149,,21,59,166,33,23,04,304,16*75
1377262634.028000    
$GPGSV,3,3,12,25,18,129,21,27,11,260,39,29,45,071,47,31,35,211,47*7C

but this returns me the following:

read.csv("sensor_0.log",sep=",")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  more columns than column names

I guess the problem is that the columns are not consistent on a per row basis.
What  I am trying to do though is to read only the lines that contain the 
$GPGLL or the $GPGLA entries (in the example they corresponds to 3rd and 4th 
line).
How can I do this in R?

Regards
A
[[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] From Strings to Variable name. When get does not work

2014-03-12 Thread Alaios
Hi all,
I would like to turn some long strings like MyString$Myfield$MySubfield into 
variables but it looks like that the get does not like lists



so for example:

 test<-list(a=2) 

test 
>$a 
[1] 2 


get("test") 
>$a 
[1] 2 


get("test$a") 
>Fehler in get("test$a") : Objekt 'test$a' nicht gefunden 

lapply(test,function(x) return (x$a)) 
>Fehler in x$a : $ operator is invalid for atomic vectors 

What should I do to read those lists I have as strings?

I would like to thank you in advance for your reply

regards
A

[[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] Lists with numbers lists and strings

2013-10-18 Thread Alaios
Dear all,
I have a list that is created like that

Spans<-list( c(837e6,842e6), 
      c(832e6,837e6), 
      c(930.1e6,935.1e6)
      )



I would like to include a second list that will contain the string that would 
correspond to the numbers at the left side. 

I would like thus inside my list to have two sublists. The first onew would be 
the Spans and the second one the Caption list.

Could you please help me understand how I can do that?

Regards
Alex

[[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] plot correlation matrix

2013-10-21 Thread Alaios
Hi all,
I am having 4 vectors like

Data: num [1:4, 1:32] -82.8 -81.8 -75.5 -107.6 -87.6 ...  

and I want to calculate the correlation between those.

Is there a graphical way in R to plot the correlations or not?

I would like to thank you in advance for your help

Regards
Alex
[[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] Where is element 30?

2013-10-22 Thread Alaios
Hi I have a vector like that

readCsvFile$V1
 [1]  30  31  32  33  34  35  36  37  38  39 310 311 312 313 314 315 316 317 318
[20] 319 320 321  20  21  22  23  24  25  26  27  28  29 210 211 212 213 214 215
[39] 216 217 218 219 220 221 222 223  40  41  42  43  44  45  46  47  48  49 410
[58] 411 412 413 414 415 416 417 418 419 420 421


and I am looking to find where the number 31 is located. So I need one function 
to return me the index of where the number 31 is.
Is there a function for that in R?

Regards
Alex
[[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] Plot.raster hides the axis layer

2013-10-24 Thread Alaios
Hi all,
I am trying to plot a raster object (I can explain why but the point is that it 
would be a raster objeçt)..

I have selected a small code to show you exactly the problem


require(raster)
test<-matrix(data=runif(1),nrow=100)
m<-raster(test)
plot(m,axes="FALSE")
axis(1,at=c(0,1),labels=c("a","b")) # THIS DOES NOT CHANGE THE INVISIBLE AXIS 
WHILE




plot(test,axes="FALSE")
axis(1,at=c(0,1),labels=c("a","b")) # WHEN I AM PLOTTING A NON RASTER OBJECT 
THE AXIS APPEARS.

Can someone explain me what I can do so a raster layer to show correctly the 
axis? Please remember that I have to do that on a raster object so coercing it 
will not help ..

I would like to thank you in advance for your help

Regards
Alex

[[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] add a color band

2013-10-25 Thread Alaios
Hi all,
I would like to ask your help to add a color band (Ι am not sure regarding the 
right term, this color band at the right of the plot "describing" values with 
their corresponding color. 

For now I have only this code



test<-matrix(data=runif(1),nrow=100)
plot(test,axes="FALSE")

axis(1,at=c(0,1),labels=c("a","b")) # 

but  I would like to add at the right  side the color legend.

How can I do that in R?

I would like to thank you in advance for your help

R.
Alex
[[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] add a color band

2013-10-25 Thread Alaios
Hi Jim and thanks for help

I will need some help to make
-the legend visible (probably at the right side of the window)
-split the legend at 0.1 steps -1,-0.9,-0.8.1 and 

-assign a color heat.color(30). I have selected orange and reds
-show me the way to change the size of legend if it would be needed




par(mar=c(7,4,4,6))
test<-matrix(data=runif(1),nrow=100)
color2D.matplot(test,axes="F",xlab="",ylab="",show.legend=FALSE) 
#,show.legend=TRUE
axis(1,at=seq(1:nrow(test)),labels=seq(201,300)) #
color.legend(11,6,11.8,9,seq(-1,1,length=10),rect.col=heat.colors(30),gradient="y")

I would like to thank you in advance for your help

Regards
Alex




On Friday, October 25, 2013 11:50 AM, Jim Lemon  wrote:
 
On 10/25/2013 08:38 PM, Alaios wrote:
> Hi all,
> I would like to ask your help to add a color band (Ι am not sure 
> regarding the right term, this color band at the right of the plot 
> "describing" values with their corresponding color.
>
> For now I have only this code
>
>
>
> test<-matrix(data=runif(1),nrow=100)
> plot(test,axes="FALSE")
>
> axis(1,at=c(0,1),labels=c("a","b")) #
>
> but  I would like to add at the right  side the color legend.

>
> How can I do that in R?
>
> I would like to thank you in advance for your help
>
Hi Alex,
If all else fails, look at color.legend (plotrix).

Jim
[[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] Compare two lists, with their sublists that have same structure

2013-10-26 Thread Alaios
Dear all,
I would like to ask your help concering two R lists.
If I did everything should have the same structure (that means the same number 
of sublists, and their sublists also the same number of sublists). What would 
change between the two lists is the contents of each element in the lists.


Could you please help me understand how I can do that in R?
I would like to thank you in advance for your help

Regards
Alex
[[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] add a color band

2013-10-26 Thread Alaios
Hi Jim and thanks for your answer... I might be too tired with my new born or 
just exhausted.

I am attaching for everyone a small data snipset that you can load


load("DataToPlotAsImage.Rdata")
require(plotrix)
browser()
test<-data
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
  
axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(104,30,112,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")

as you can see I have problems where the legend appears. My par("usr"  returned 
me
par("usr")
# [1]   0 351   0 200

but I am not sure how to read that to place the legend at a useful place. 
second I am not sure why the image is so full with black rows..

What I want is to have the legend visible
and later on customize the x axis to write custom string of different size... 
First I need though to fix the more severe problems as I have described

Regards
Alex




On Friday, October 25, 2013 11:45 PM, Jim Lemon  wrote:
 
On 10/25/2013 11:16 PM, Alaios wrote:
> Hi Jim and thanks for help
>
> I will need some help to make
> -the legend visible (probably at the right side of the window)
> -split the legend at 0.1 steps -1,-0.9,-0.8.1 and
> -assign a color heat.color(30). I have selected orange and reds
> -show me the way to change the size of legend if it would be needed
>
>
>
> par(mar=c(7,4,4,6))
> test<-matrix(data=runif(1),nrow=100)
> color2D.matplot(test,axes="F",xlab="",ylab="",show.legend=FALSE)
> #,show.legend=TRUE
> axis(1,at=seq(1:nrow(test)),labels=seq(201,300)) #
> color.legend(11,6,11.8,9,seq(-1,1,length=10),rect.col=heat.colors(30),gradient="y")
>
Hi Alex,
You can do this in at least two ways. The first example uses the 
color.scale function to assign colors close to those of heat.colors. The 
second shows how to use heat.colors if you want that.

library(plotrix)
par(mar=c(7,4,4,6))
test<-matrix(data=runif(1),nrow=100)
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
axis(1,at=seq(1:nrow(test)),labels=seq(201,300))
# use par("usr") to find out the plot dimensions,
# then place the legend where you want it
color.legend(104,30,112,70,seq(-1,1,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")
# now try it with heat.colors
test.cut<-matrix(as.numeric(cut(test,breaks=seq(0,1,length.out=30))),nrow=100)
color2D.matplot(test.cut,axes="F",xlab="",ylab="",main="heat.colors",
  cellcolors=heat.colors(30)[test.cut],show.legend=FALSE)
axis(1,at=seq(1:nrow(test)),labels=seq(201,300))
color.legend(104,30,112,70,seq(-1,1,length=11),
  align="rb",rect.col=heat.colors(30),gradient="y")


Jim__
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 avoid this warning message

2013-10-27 Thread Alaios
Dear all,
I would like to ask you how I can avoid this warning I am getting when I am 
writing some results in a text file

5: In write.table(x = cor(t(collectMean_UL), t(collectMean_DL)),  ... :
  appending column names to file


the code that saves to the file look like:

 write(x="TEMPERATURE",file=paste(Folder,"/Corr_",".txt",sep=""),append="TRUE") 
   
 write.table(x=cor(t(Data)),file=paste(Folder,"/Cor_",".txt",sep=""),eol = 
"\r\n",append="TRUE")

if someone can help on that...

I would like to thank you in advance for your reply

Regards
Alex

[[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] add a color band

2013-10-28 Thread Alaios


Hi Jim and thanks for your answer... I might be too tired with my new born or 
just exhausted.

I am sharing for everyone a small data snipset that you can load
https://www.dropbox.com/s/fh8jhwujgunmtrb/DataToPlotAsImage.Rdata



load("DataToPlotAsImage.Rdata")
require(plotrix)
browser()
test<-data
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
  
axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(104,30,112,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")

as you can see I have problems where the legend appears. My par("usr"  returned 
me
par("usr")
# [1]   0 351   0 200

but I am not sure how to read that to place the legend at a useful place. 
second I am not sure why the image is so full with black rows..

What I want is to have the legend visible
and later on customize the x axis to write custom string of different 
size... First I need though to fix the more severe problems as I have 
described

RegardsAlex



On Sunday, October 27, 2013 12:25 PM, Jim Lemon  wrote:
 
On 10/27/2013 08:39 AM, Alaios wrote:
> Hi Jim and thanks for your answer... I might be too tired with my new
> born or just exhausted.
>
> I am attaching for everyone a small data snipset that you can load
>
>
> load("DataToPlotAsImage.Rdata")
> require(plotrix)
> browser()
> test<-data
> # this transforms the values of "test" into red->yellow
> color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
> extremes=c("#FF","#00"),show.legend=FALSE)
>
> axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
> color.legend(104,30,112,70,seq(-110,-30,length=11),
> align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")
>
> as you can see I have problems where the legend appears. My par("usr"
> returned me
> par("usr")
> # [1] 0 351 0 200
>
> but I am not sure how to read that to place the legend at a useful place.
> second I am not sure why the image is so full with black rows..
>
> What I want is to have the legend visible
> and later on customize the x axis to write custom string of different
> size... First I need though to fix the more severe problems as I have
> described
>
Hi Alex,
I'm not sure why you have created a copy of "data" to plot it. I can get 
quite a sensible plot using this:

par(mar=c(5,4,4,5))
color2D.matplot(data,1,c(0,1),0,xlab="",ylab="",
  main="color.scale",xrange=c(-110,-50),border=NA)
color.legend(357,30,370,100,seq(-110,-50,length.out=6),
  align="rb",rect.col=color.scale(1:6,1,c(0,1),0),
  gradient="y")

Notice several things. First, when you have a large number of cells in a 
plot like this, setting the border to NA means that you don't get mostly 
borders (default = black) in the plot. The second thing is that your 
data range is -107.18150 to -54.07662. In order to get rounded numbers 
in your legend, I have set the xrange argument to -110 to -50. This 
gives a neat looking legend that spans your data, a bit like the
"pretty" function would do. It also means that the color mapping is to 
that range and is the same in the legend as in the plot. I have left 
enough space on the right of the plot to fit in the legend, as that was 
where you said you wanted it in your last email. What par("usr") tells 
you is the dimensions of the plot in user units. Here it is x=0 at the 
left, x=351 at the right, y=0 at the bottom and y=200 at the top.


Jim
[[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] Create Time Lists with a for loop

2013-10-28 Thread Alaios
Dear all, 
in my code I have written the following list

TimeFramesShort <-list(c(strptime("2011-10-12 10:59:00","%Y-%m-%d 
%H:%M:%S"),strptime("2011-10-13 11:02:00","%Y-%m-%d %H:%M:%S"))  # 
rest items were truncated


I was wondering if could somehow  take the first element of the list and create 
element that are only 5 minutes apart something like
list(c(strptime("2011-10-12 10:59:00","%Y-%m-%d %H:%M:%S"),strptime("2011-10-12 
11:04:00","%Y-%m-%d %H:%M:%S"),
c(strptime("2011-10-12 11:04:00","%Y-%m-%d %H:%M:%S"),strptime("2011-10-12 
11:09:00","%Y-%m-%d %H:%M:%S"),
c(strptime("2011-10-12 11:09:00","%Y-%m-%d %H:%M:%S"),strptime("2011-10-12 
11:13:00","%Y-%m-%d %H:%M:%S")
...
and so on.

The problem I see is that pure string manipulation will not work as after one 
hour that should also make changes in the hours.

Regards
Alex 
[[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] TelosB external modules, guide

2013-10-29 Thread Alaios
Hi all,
I would like to ask your help regarding connecting external modules to telosb. 
I have found that tiny os offers many possibilities for that as 

ADC,
GPIOs, SPI, UART, I2C

I have never learned anything regarding those. Can someone please let me know 
if there is any simple
guide on these "interfaces" to show with a primitive example how to start with?

I would like to thank you in advance for your help

Regards
Alex
[[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] add a color bar in a plot

2013-10-29 Thread Alaios
Hi all,
I am trying to add a color legend to my plot. As an example I am giving you a 
bit of code that you can run.
I am sharing for everyone a small data snipset that you can load
https://www.dropbox.com/s/fh8jhwujgunmtrb/DataToPlotAsImage.Rdata



load("DataToPlotAsImage.Rdata")
require(plotrix)
browser()
test<-data
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
  
axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(104,30,112,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")

as you can see I have problems where the legend appears. My par("usr"  returned 
me
par("usr")
# [1]   0 351   0 200

but I am not sure how to read that to place the legend at a useful place. 
second I am not sure why the image is so full with black rows..

What I want is to have the legend visible
and later on customize the x axis to write custom string of different 
size... First I need though to fix the more severe problems as I have 
described

RegardsAlex

[[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] Select fixed number of elements

2013-10-30 Thread Alaios
Hi all,
I have in my code some vectors that are not of equal size. I would like to be 
able for each of these vectors select 6 elements that are (almost) equally 
spaced. So the first one would be at (or close) to the beginning the last one 
at (or close) to the end and the other 4 equally spaced between first and last 
element.

How can I do something like that on a vector of not known size?

I would like to thank you in advance for your help

Regards
Alex
[[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] Select fixed number of elements

2013-10-30 Thread Alaios
Thumbs up! It worked!





On Wednesday, October 30, 2013 9:41 AM, Gerrit Eichner 
 wrote:
 
Hello, Alaois,

if x is your vector maybe

n <- length( x)
positions <- trunc( quantile( seq( n), prob = 0:5/5))
x[ positions]

comes close to what you want.

  Hth  --  Gerrit


> Hi all, I have in my code some vectors that are not of equal size. I 
> would like to be able for each of these vectors select 6 elements that 
> are (almost) equally spaced. So the first one would be at (or close) to 
> the beginning the last one at (or close) to the end and the other 4 
> equally spaced between first and last element.
>
> How can I do something like that on a vector of not known size?
>
> I would like to thank you in advance for your help
>
> Regards
> Alex
>     [[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.
[[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 me align the legend bar

2013-10-30 Thread Alaios
Hi,
I have some code that you can simply execute:

require(plotrix)

test<-matrix(data=rnorm(1,-100,5),nrow=100)
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
 
axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(84,30,125,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")


What I would like to do is to make space at the right for the color band . The 
band should have one color from -110 to -30 with scales of 10.

Can someone help me with that?

Regards
Alex
[[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] remap values from one vector to the other

2013-10-31 Thread Alaios
Hi everyone, 
I am plotting some legend and I am using the axis(at=..) to specify the place 
to plot the marks I want.

My plotted data have ncol(x) so the at places have values that span from 1 to 
ncol(x)

there I would like to be able to map values that go from 880e6 to 1020e6.
so 
880e6 remaps to 1


1020e6 repams to ncol(x)

what I do not know how to do is to remap the values that are between 880e6 and 
1020e6 between then 1 and ncol(x).

Can someone help me find an appropriate function for that?

I would like to thank you in advance for your help

Regards
Alex
[[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] add a color band

2013-11-04 Thread Alaios
Hi Jim Lemon,
thanks for the help, I appreciate this.

right now my code looks like.


par(mar=c(5,4,4,5))
color2D.matplot(data,1,c(0,1),0,xlab="",ylab="Spans",
  main="color.scale",xrange=c(-110,-50),border=NA,axes=F)
color.legend(357,30,370,100,seq(-110,-50,length.out=13),
  align="rb",rect.col=color.scale(1:13,1,c(0,1),0),
  gradient="y")


my major problem now is that the 

a. text in  the color bar is squeezed so -50 overlaps with -60 and so on
b. for some reason the color bar sometimes (the same code is called for all the 
data matrices I have) is misaligned  in different positions each time

Could you please also help me with those two?

Regards
Alex




On Monday, October 28, 2013 9:00 AM, Alaios  wrote:
 


Hi Jim and thanks for your answer... I might be too tired with my new born or 
just exhausted.

I am sharing for everyone a small data snipset that you can load
https://www.dropbox.com/s/fh8jhwujgunmtrb/DataToPlotAsImage.Rdata



load("DataToPlotAsImage.Rdata")
require(plotrix)
browser()
test<-data
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
  extremes=c("#FF","#00"),show.legend=FALSE)
  
axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(104,30,112,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")

as you can see I have problems where the legend appears. My par("usr"  returned 
me
par("usr")
# [1]   0 351   0 200

but I am not sure how to read that to place the legend at a useful place. 
second I am not sure why the image is so full with black rows..

What I want is to have the legend visible
and later on customize the x axis to write custom string of different 
size... First I need though to fix the more severe problems as I have 
described

RegardsAlex




On Sunday, October 27, 2013 12:25 PM, Jim Lemon  wrote:

On 10/27/2013 08:39 AM, Alaios wrote:
> Hi Jim and thanks for your answer... I might be too tired with my new
> born or just exhausted.
>
> I am attaching for everyone a small data snipset that you can load
>
>
> load("DataToPlotAsImage.Rdata")
> require(plotrix)
> browser()
> test<-data
> # this transforms the values of "test" into red->yellow
> color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
> extremes=c("#FF","#00"),show.legend=FALSE)
>
> axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
> color.legend(104,30,112,70,seq(-110,-30,length=11),
> align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")
>
> as you can see I have problems where the legend appears. My par("usr"
> returned me
> par("usr")
> # [1] 0 351 0 200
>
> but I am not sure how to read that to place the legend at a useful place.
> second I am not sure why the image is so full with black rows..
>
> What I want is to have the legend visible
> and later on customize the x axis to write custom string of different
> size... First I need though to fix the more severe problems as I have
> described
>
Hi Alex,
I'm not sure why you have created a copy of "data" to plot it. I can get 
quite a sensible plot using this:

par(mar=c(5,4,4,5))
color2D.matplot(data,1,c(0,1),0,xlab="",ylab="",
  main="color.scale",xrange=c(-110,-50),border=NA)
color.legend(357,30,370,100,seq(-110,-50,length.out=6),
  align="rb",rect.col=color.scale(1:6,1,c(0,1),0),
  gradient="y")

Notice several things. First, when you have a large number of cells in a 
plot like this, setting the border to NA means that you don't get mostly 
borders (default = black) in the plot. The second thing is that your 
data range is -107.18150 to -54.07662. In order to get rounded numbers 
in your legend, I have set the xrange argument to -110 to -50. This 
gives a neat looking legend that spans your data, a bit like the
"pretty" function would do. It also means that the color mapping is to 
that range and is the same in the legend as in the plot. I have left 
enough space on the right of the plot to fit in the legend, as that was 
where you said you wanted it in your last email. What par("usr") tells 
you is the dimensions of the plot in user units. Here it is x=0 at the 
left, x=351 at the right, y=0 at the bottom and y=200 at the top.


Jim
    [[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.
[[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] add a color band

2013-11-04 Thread Alaios
Hi Jim,
thanks for the answer! I toyed around as you said and now they look cool and 
sexy! many thanks!

Do you know if there is a way to compress a bit the output? The image type of 
functions have the useRaster parameter to set to have a "compressed" output. 
Right now the produced plots are around 400kBytes which is a lot and I am 
looking for ways to reduce image size.

I would like to thank you for you reply 

Alex





On Monday, November 4, 2013 11:59 AM, Jim Lemon  wrote:
 
On 11/04/2013 08:09 PM, Alaios wrote:
> Hi Jim Lemon,
> thanks for the help, I appreciate this.
>
> right now my code looks like.
>
>
> par(mar=c(5,4,4,5))
> color2D.matplot(data,1,c(0,1),0,xlab="",ylab="Spans",
> main="color.scale",xrange=c(-110,-50),border=NA,axes=F)
> color.legend(357,30,370,100,seq(-110,-50,length.out=13),
> align="rb",rect.col=color.scale(1:13,1,c(0,1),0),
> gradient="y")
>
>
> my major problem now is that the
> a. text in the color bar is squeezed so -50 overlaps with -60 and so on
> b. for some reason the color bar sometimes (the same code is called for
> all the data matrices I have) is misaligned in different positions each time
>
> Could you please also help me with those two?
>
Hi Alex,
For your first question, I would simply extend the color legend vertically:

color.legend(357,30,370,150,seq(-110,-50,length.out=13),
  align="rb",rect.col=color.scale(1:13,1,c(0,1),0),
  gradient="y")

For the second one, you obviously have different dimensions for the data 
matrices. So, let's step through a method for getting the legend 
position and size from the plot itself. As I have written a few times 
previously, par("usr") gives you the dimensions of the plot in user 
units. For the example above, the dimensions were:

x - 0->351
y - 0->200

With a bit of arithmetic, you can work out that the legend positions in 
the above are:

xylim<-par("usr")
# x position of lower left corner of legend
xl<-xylim[2]+diff(xylim[1:2])*0.017
# y position of lower left corner
yb<-xylim[3]+diff(xylim[3:4])*0.15
# x position of upper right corner of legend
xr<-xylim[2]+diff(xylim[1:2])*0.054
# y position of upper right corner
yt<-xylim[3]+diff(xylim[3:4])*0.75

Having these lines means that you can get the position and size of the 
legend about right from the information provided by par("usr") even if 
you change the number of cells in the matrix passed to color2D.matplot. 
Then you would call:

color.legend(xl,yb,xr,yt,seq(-110,-50,length.out=13),
  align="rb",rect.col=color.scale(1:13,1,c(0,1),0),
  gradient="y")

unless of course you wanted to change the values in the scale markings. 
I'll leave that for you to work out.


Jim
[[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] convert one digit numbers to two digits one

2013-11-06 Thread Alaios
Hi all,
the following returns the hour and the minutes

paste(DataSet$TimeStamps[selectedInterval$start,4], 
DataSet$TimeStamps[selectedInterval$start,5],sep=":")
[1] "12:3"

the problem is that from these two I want to create a time stamp so 12:03. The 
problem is that the number 3 is not converted to 03. Is there an easy way when 
I have one digit integer to add a zero in the front? Two digits integers are 
working fine so far, 12:19, or 12:45 would appear correctly

I would like to thank you in advance for your help

Regards
Alex
[[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] Colour Legend text, in a print color2D.matplot

2013-11-10 Thread Alaios
Hi all,

I am plotting very nice looking mattrices with  plotrin...

so far so good, I would like though to ask you if it would be possible to add 
at the bottom of the color.legend (this lovely color bar that maps colors to 
numbers).
Would that be possible to do that?

I would like to thank you in advance for your reply

Regards
Alex
[[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] Plotrix: Add text below the color- legend.

2013-11-10 Thread Alaios
Hi all,
I am plotting very nice and sexy images with plotrix :)
so far so good, I would like though to ask you if it would be possible to add 
at the bottom of the color.legend (this lovely color bar that maps colors to 
numbers).
Would that be possible to do that?

I would like to thank you in advance for your reply

Regards
Alex
[[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] Colour Legend text, in a print color2D.matplot

2013-11-10 Thread Alaios
Thanks! It worked. 

Regards
Alex





On Monday, November 11, 2013 12:02 AM, Jim Lemon  wrote:
 
On 11/11/2013 04:57 AM, Alaios wrote:

> Hi all,
>
> I am plotting very nice looking mattrices with  plotrin...
>
> so far so good, I would like though to ask you if it would be possible to add 
> at the bottom of the color.legend (this lovely color bar that maps colors to 
> numbers).
> Would that be possible to do that?
>
Hi Alex,
It is not too difficult:

# first allow printing outside the plot
par(xpd=TRUE)
# get the x component of the label
# from the values passed to color.legend
# see the help page
labelx<-(xl+xr)/2
# get the y coordinate from the y value
labely<-yb-strheight("M")
# display the label
text(labelx,labely,mylabel)
# restore the clipping
par(xpd=FALSE)

Jim
[[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] Colour Legend text, in a print color2D.matplot

2013-11-12 Thread Alaios
Hi Jim, it worked nicely.
par(mar) looks to control the space at the bottom left right and top.. What If 
I want to increase a bit the distance between the plotted matrix and the added 
color legend ? They look to be at my version slightly packed together.

Regards
Alex





On Monday, November 11, 2013 3:07 AM, Alaios  wrote:
 
Thanks! It worked. 

Regards
Alex






On Monday, November 11, 2013 12:02 AM, Jim Lemon  wrote:

On 11/11/2013 04:57 AM, Alaios wrote:

> Hi all,
>
> I am plotting very nice looking mattrices with  plotrin...
>
> so far so good, I would like though to ask you if it would be possible to add 
> at the bottom of the color.legend (this lovely color bar that maps colors to 
> numbers).
> Would that be possible to do that?
>
Hi Alex,
It is not too difficult:

# first allow printing outside the plot
par(xpd=TRUE)
# get the x component of the label
# from the values passed to color.legend
# see the help page
labelx<-(xl+xr)/2
# get the y coordinate from the y value
labely<-yb-strheight("M")
# display the label
text(labelx,labely,mylabel)
# restore the clipping
par(xpd=FALSE)

Jim
    [[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.
[[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] Handle Gps coordinates

2013-11-12 Thread Alaios
Dear all,
I would like to ask you if there are any gps libraries.


I would like to be able to handle them,
-like calculate distances in meters between gps locations,
-or find which gps location is closer to a list of gps locations.

Is there something like that in R?

I would like to tthank you in advance for your reply

Regards
Alex
[[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] Grid type of sampling in geodata

2013-11-13 Thread Alaios
Hi all,
I have spatial field created with grf and I was wondering if I can sample in 
lines, something that can resemble sampling outdoors at the streets.
Random sampling looks to far of what I want to have.

there is in geodata package the sample.geodata but this looks like to be random 
samples.

I would like to thank you in advance for your help

Regards
A.
[[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] save table to txt file in a printable form

2013-11-19 Thread Alaios
Hi there,
I would like to save tabular (in R just matrices) in a txt file but in a way 
that they would be somehow readable.
That means keeping columns aligned and rows so one can read easily for example 
the 2,3 element.

IS there a way to do that in R?
capture.output for example does not produce tables in the way I want to have 
those.

Regards
Alex
[[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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread alaios

 Hello to the community .
First post :)
I would like to ask you which text editor do you use in Linux and how did
you setup the syntax highlightning?
one more question is it possible to debug any program in R by inserting
breakpoints?

I would like to thank you in advance for your help
Best Regards
Alex
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Syntax-Highlightning-and-Editor-for-Linux-tp2300072p2300072.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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Alaios
I would like to thank you for your immediate reply.
Actually I do not like vim and emacs.. I am trying to find an editor with a gui 
that will work fine in Linux.

One more question. If I am editing a file using my external text editor is it 
possible to execute directly one of the functions that are inside the file 
without executing the source("myfile.R") command first?

Best Regards
Alex



- Original Message 
From: Duncan Murdoch 
To: alaios 
Cc: r-help@r-project.org
Sent: Fri, July 23, 2010 2:13:48 PM
Subject: Re: [R] Syntax Highlightning and Editor for Linux

On 23/07/2010 8:08 AM, alaios wrote:
>  Hello to the community .
> First post :)
> I would like to ask you which text editor do you use in Linux and how did
> you setup the syntax highlightning?
>  

I don't use Linux, but I think the most popular editors there are vim and 
emacs, 
the latter with ESS. 

> one more question is it possible to debug any program in R by inserting
> breakpoints?
> 
>  

Yes, see the setBreakpoint() and trace() functions.

Duncan Murdoch

> I would like to thank you in advance for your help
> Best Regards
> Alex
>

__
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] Syntax Highlightning and Editor for Linux

2010-07-23 Thread Alaios
I would like oto thank everyone for the replies.
I instaled rkward.. It looks like an editor.. Is it possible to execute also 
your code from the text editor.
If there is a function call myfunc inside my file test.R
Is it possible to exectute the function from the rwkard?

Best Regards
Alex





From: Federico Andreis 
To: Rainer M Krug 

Sent: Fri, July 23, 2010 3:46:08 PM
Subject: Re: [R] Syntax Highlightning and Editor for Linux

I have been trying emacs with ess, Kate, plain gedit..nothing really satisfied 
me..
[[elided Yahoo spam]]

it supports split screen with R terminal window (you can also personalize 
colour 
if, like me, do like to
stick with old habits :) ), moreover gedit has a brackets completion and a 
brackets highlight plugin which are very useful.


check it out here

http://www.stattler.com/article/using-gedit-or-rgedit-r

simple "send code to terminal" shortcuts (much simpler than emacs, in my 
[[elided Yahoo spam]]

/federico



On Fri, Jul 23, 2010 at 2:42 PM, Rainer M Krug  wrote:

-BEGIN PGP SIGNED MESSAGE-
>Hash: SHA1
>
>
>On 23/07/2010 14:17, Alaios wrote:
>> I would like to thank you for your immediate reply.
>> Actually I do not like vim and emacs.. I am trying to find an editor with a 
>gui
>> that will work fine in Linux.
>Well - you are missing out with not using emacs + ess - but it is quite
>a learning curve. Despite this:
>
>Try rkward - syntax highlighting and many other nice features.
>
>Another option: eclipse with statet plugin(
>http://www.walware.de/goto/statet)
>
>Cheers,
>
>Rainer
>
>>
>> One more question. If I am editing a file using my external text editor is it
>> possible to execute directly one of the functions that are inside the file
>> without executing the source("myfile.R") command first?
>>
>> Best Regards
>> Alex
>>
>>
>>
>> - Original Message 
>> From: Duncan Murdoch 

>> Cc: r-help@r-project.org
>> Sent: Fri, July 23, 2010 2:13:48 PM
>> Subject: Re: [R] Syntax Highlightning and Editor for Linux
>>
>> On 23/07/2010 8:08 AM, alaios wrote:
>>>  Hello to the community .
>>> First post :)
>>> I would like to ask you which text editor do you use in Linux and how did
>>> you setup the syntax highlightning?
>>>
>>
>> I don't use Linux, but I think the most popular editors there are vim and 
>>emacs,
>> the latter with ESS.
>>
>>> one more question is it possible to debug any program in R by inserting
>>> breakpoints?
>>>
>>>
>>
>> Yes, see the setBreakpoint() and trace() functions.
>>
>> Duncan Murdoch
>>
>>> I would like to thank you in advance for your help
>>> Best Regards
>>> Alex
>>>
>>
>> __
>> 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.
>
>
>- --
>Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>Biology, UCT), Dipl. Phys. (Germany)
>
>Centre of Excellence for Invasion Biology
>Natural Sciences Building
>Office Suite 2039
>Stellenbosch University
>Main Campus, Merriman Avenue
>Stellenbosch
>South Africa
>
>Tel:+33 - (0)9 53 10 27 44
>Cell:   +27 - (0)8 39 47 90 42
>Fax (SA):   +27 - (0)8 65 16 27 82
>Fax (D) :   +49 - (0)3 21 21 25 22 44
>Fax (FR):   +33 - (0)9 58 10 27 44
>email:  rai...@krugs.de
>
>Skype:  RMkrug
>-BEGIN PGP SIGNATURE-
>Version: GnuPG v1.4.10 (GNU/Linux)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
>iEYEARECAAYFAkxJjjMACgkQoYgNqgF2egqmgACeK5OXtqsKvAcK1Pyli6zlLpW6
>ttkAoIzeKgwKeo7cj4oH+jSOr8QMgFFP
>=B7JP
>-END PGP SIGNATURE-
>
>
>__
>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.
>



  
[[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] Creating a map .

2010-07-26 Thread Alaios
Hello.
I would try to explain what I would like to implement so to suggest me what to 
try out.

I would like to create an area of X*X  km that would be used to "Simulate" an 
area map (eg. city's area, suburban area). 

-X would be a parameter so I do not want it to be fixed
-In this map I would like to place users (people), thus I do not know in 
advance 
if in one place there would be one,two, or more users..
-I would also like to not have fixed resolution in my map and specify it as a 
parameter during run-time. In my X*X area I would like sometimes to have 
resolution of 1Km and others resolution of 10 meters. As resolution increases 
(1 
km->100m->10m) less users would be found in the same "place".
-In every "place" I would like to specify some parameters (eg. number of users, 
characteristics of users, energy consumption per user). I do not know in 
advance 
how much data I would need per user. Ofc 10 parameters per place might be ok 
but 
a not fixed approach is better.

My first thoughts were to use an array and actually define an array of X*X 
dimension where X is defined at run time as parameter. The problem with this 
approach is that I do not have variable resolution in this area as I have the 
constant number of X*X places only. Also one more problem is that the cels of 
the array (where cell is used to simulate "place") can not be used to story 
many 
parameters but only a single numerical value).

What do you suggest me to try looking at and what made up your decision?

I would like to thank everyone that reached to this point reading all my big 
text.

Best Regards
Alex.

__
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] what is a vignette?

2010-07-26 Thread Alaios
I am trying to find a simple R guide that explain what a vignette is but so far 
I didnt make any progress. I tried to search inside R's built in help.start() 
but it only returns results how to see vignettes.

So could you please tell me what a vignette is and if you can also could you 
give some simple guide that I can always use to read about these things?

Best Regards
Alex

__
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] "=" vs "<-" operator

2010-07-26 Thread Alaios
Hello
I notice that in Linux the "=" operator works like the "<-" operator
So a=3 is similar to a<-3.
Could you please verify me that is correct? I would like to use "=" operator. 
Do 
you think that might be a problem in the future?

Best Regards
Alex

__
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] See what is inside a matrix

2010-09-09 Thread Alaios
Hello everyone.. Is there any graphical tool to help me see what is inside a 
matrix? I have 100x100 dimensions matrix and as you already know as it does not 
fit on my screen R splits it into pieces.

I would like to thank you in advance for your help
Best Regards
Alex



  
[[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] Line integral with R

2010-09-13 Thread Alaios
Hello.
I would like to calculate with R
the weighted line integral of a loss field.
Where should I start searching about weighted integration in R?

I would like to thank you in advance for your help

Best Regards
Alex


  
[[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] print matrix values and if statement

2010-09-13 Thread Alaios
Hello everyone,
I have a 2x2 matrix filled with zeros and some more values around zeros. I 
would 
like to print only the non-zero values 

and 
to keep the coords of the places that the values are not zero.

Could you please help me with that?

I would like to thank you in advance for your help
Best Regards
Alex



  
[[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] array of objects

2010-09-13 Thread Alaios
Hello everyone.
I would like to create some agents that span over a specific area map.Every 
agent needs to have its own data structures like one or two matrices and one 
list.

I think that the best way to do this is to create objects and every instance of 
an object will be used for a single agent. 

The number of agents is not predetermined and it varies for any execution.
So I read this value from the command line interface and then I would like to 
initiate so many objects as the agents. I think that the best way to do that is 
to create using a for loop a list containing as many objects as the agents are. 


Is it possible to help me do that with R... the tricky part is not only to 
create these objects but also having some nice way to address them... Perhaps 
an 
index i might be used for that.

I would like to thank you in advance for your help

Best Regards
Alex



  
[[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] Object oriented programming in R.

2010-09-14 Thread Alaios
Hello everyone.
I would like to create many objects with R. Does R support objects?

The number of objects needed is not predetermined and it is a parameter 
specified by the user.
If the user selects to create many objects like 100, would it be possible to 
handle each one by some index?

I would like to thank you in advance for your help.


Best Regards
Alex


  
[[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] Object oriented programming in R.

2010-09-14 Thread Alaios
Thank you very much. I checked the tutorials that on that list but still I do 
not know how to create many objects of the same type. Can you please help me 
with that?

Best Regards
Alex





From: Tal Galili 

Cc: Rhelp 
Sent: Tue, September 14, 2010 10:11:36 AM
Subject: Re: [R] Object oriented programming in R.


Hello Alaios,
I see a bunch of good materials here:
http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R


Did you look into them ?

Contact 
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | 
www.r-statistics.com (English)
--








Hello everyone.
>I would like to create many objects with R. Does R support objects?
>
>The number of objects needed is not predetermined and it is a parameter
>specified by the user.
>If the user selects to create many objects like 100, would it be possible to
>handle each one by some index?
>
>I would like to thank you in advance for your help.
>
>
>Best Regards
>Alex
>
>
>
>   [[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.
>



  
[[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] Object oriented programming in R.

2010-09-14 Thread Alaios
Here are some more information:
I would like to create some agents that span over a specific area map.Every 
agent needs to have its own data structures like one or two matrices and one 
list.

I think that the best way to do this is to create objects and every instance of 
an object will be used for a single agent. 

The number of agents is not predetermined and it varies for any execution.
So I read this value from the command line interface and then I would like to 
initiate so many objects as the agents. I think that the best way to do that is 
to create using a for loop a list containing as many objects as the agents are. 

I would like to thank you in advance for your help

Best Regards
Alex




From: jim holtman 

Cc: Tal Galili ; Rhelp 
Sent: Tue, September 14, 2010 1:40:37 PM
Subject: Re: [R] Object oriented programming in R.

It depends on what you mean by objects.  If you are just looking at
creating many named variables that are going to hold values (e.g.,
reading in data from several files that you want to correlate
separately), then consider the use of 'lists'.  Can you provide a
little more detail on exactly the problem that you are trying to
solve, and then maybe we can propose a solution.


> Thank you very much. I checked the tutorials that on that list but still I do
> not know how to create many objects of the same type. Can you please help me
> with that?
>
> Best Regards
> Alex
>
>
>
>
> 
> From: Tal Galili 
>
> Cc: Rhelp 
> Sent: Tue, September 14, 2010 10:11:36 AM
> Subject: Re: [R] Object oriented programming in R.
>
>
> Hello Alaios,
> I see a bunch of good materials here:
>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>R
>
>
> Did you look into them ?
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>--
>-
>
>
>
>
>
>
>
>
> Hello everyone.
>>I would like to create many objects with R. Does R support objects?
>>
>>The number of objects needed is not predetermined and it is a parameter
>>specified by the user.
>>If the user selects to create many objects like 100, would it be possible to
>>handle each one by some index?
>>
>>I would like to thank you in advance for your help.
>>
>>
>>Best Regards
>>Alex
>>
>>
>>
>>   [[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.
>>
>
>
>
>
>[[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.
>



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

What is the problem that you are trying to solve?



  
[[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] Object oriented programming in R.

2010-09-14 Thread Alaios
I would like to thank you very much all that you helped me so far.
So I tried to check how the following works

fred <- list(happy = 1:10, name = "squash")
rep(fred, 5)

This returns the following :

> fred[1]
$happy
 [1]  1  2  3  4  5  6  7  8  9 10


> fred[2]
$name
[1] "squash"

What I am trying to do is to address the number 5 of the fred[1] $happy value.
I tried something like fred[1][5] fred[1,5]
but it didn't work

I would like to thank you in advance for your help

Best Regards
Alex





From: Dennis Murphy 

Cc: Rhelp 
Sent: Tue, September 14, 2010 3:13:37 PM
Subject: Re: [R] Object oriented programming in R.

Hi:

You could create a list of lists, where the outer list would be between agents 
and the inner list within agents. The inner list could have the 'matrices and 
one list' as separate components for each agent. Of course, you would have to 
be 
able to keep all of this straight :)

HTH,
Dennis




Here are some more information:
>I would like to create some agents that span over a specific area map.Every
>agent needs to have its own data structures like one or two matrices and one
>list.
>
>I think that the best way to do this is to create objects and every instance of
>an object will be used for a single agent.
>
>The number of agents is not predetermined and it varies for any execution.
>So I read this value from the command line interface and then I would like to
>initiate so many objects as the agents. I think that the best way to do that is
>to create using a for loop a list containing as many objects as the agents are.
>
>
>I would like to thank you in advance for your help
>
>Best Regards
>Alex
>
>
>
>
>From: jim holtman 
>
>Cc: Tal Galili ; Rhelp 
>Sent: Tue, September 14, 2010 1:40:37 PM
>
>Subject: Re: [R] Object oriented programming in R.
>
>
>It depends on what you mean by objects.  If you are just looking at
>creating many named variables that are going to hold values (e.g.,
>reading in data from several files that you want to correlate
>separately), then consider the use of 'lists'.  Can you provide a
>little more detail on exactly the problem that you are trying to
>solve, and then maybe we can propose a solution.
>
>
>
>> Thank you very much. I checked the tutorials that on that list but still I do
>> not know how to create many objects of the same type. Can you please help me
>> with that?
>>
>> Best Regards
>> Alex
>>
>>
>>
>>
>> 
>> From: Tal Galili 
>>
>> Cc: Rhelp 
>> Sent: Tue, September 14, 2010 10:11:36 AM
>> Subject: Re: [R] Object oriented programming in R.
>>
>>
>> Hello Alaios,
>> I see a bunch of good materials here:
>>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>>
>>R
>>
>>
>> Did you look into them ?
>>
>> Contact
>> Details:---
>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>--
>>
>>-
>>
>>
>>
>>
>>
>>
>>
>>
>> Hello everyone.
>>>I would like to create many objects with R. Does R support objects?
>>>
>>>The number of objects needed is not predetermined and it is a parameter
>>>specified by the user.
>>>If the user selects to create many objects like 100, would it be possible to
>>>handle each one by some index?
>>>
>>>I would like to thank you in advance for your help.
>>>
>>>
>>>Best Regards
>>>Alex
>>>
>>>
>>>
>>>   [[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.
>>>
>>
>>
>>
>>
>>[[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 comme

[R] Interpolate? a line

2010-09-15 Thread Alaios
Hello everyone. 
I have created a 100*100 matrix in R.
Let's now say that I have a line that starts from (2,3) point and ends to the 
(62,34) point. In other words this line starts at cell (2,3) and ends at cell 
(62,34).

Is it possible to get by some R function all the matrix's cells that this line 
transverses?

I would like to thank you for your feedback.

Best Regards
Alex


  
[[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] Interpolate? a line

2010-09-15 Thread Alaios
Thank you very much. I am trying to execute it line by line to get some 
understanding how this works.
Could you please explain me what these two lines do?

tie <- m[,2] == c(-Inf, m[-nrow(m),2])
m <- m[ !tie, ]

I would like to thank you in advance for your help

Best Regards
Alex





From: Michael Bedward 

Cc: Rhelp 
Sent: Wed, September 15, 2010 12:52:45 PM
Subject: Re: [R] Interpolate? a line

Hello Alex,

Here is one way to do it. It works but it's not pretty :)

interp <- approx(c(2, 62), c(3, 34), method="linear", xout=2:62)
m <- matrix(c(interp$x, round(interp$y)), ncol=2)
tie <- m[,2] == c(-Inf, m[-nrow(m),2])
m <- m[ !tie, ]

You might want to examine the result like this...

plot(m)  # plots points
lines(c(2,26), c(3, 34))  # overlay line for comparison

Michael



  
[[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 me understand how things work.

2010-09-16 Thread Alaios
Hello I have some strange output from R and I try to understand how R works.

Could you please help me with that?

temp <- rbind (c(10,1),c(99,98))
> temp
 [,1] [,2]
[1,]   101
[2,]   99   98


> dist(temp)
 1
2   131.6435


> sqrt(dist(temp))
 1
2   11.47360

so far so good.

until the nex line: when I try to do what i did before but adding the 1/(what I 
did before). I was expecting a number as a result of the division but 
unfortunately I took the following:

 1/sqrt(dist(temp))
[1] 0.08715662
attr(,"Size")
[1] 2
attr(,"Diag")
[1] FALSE
attr(,"Upper")
[1] FALSE
attr(,"method")
[1] "euclidean"
attr(,"call")
dist(x = temp)
attr(,"class")
[1] "dist"


Could you please help me understand what is this about?

I would like to thank you in advance for your help
Best REgards
Alex



  
[[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] help me understand how things work.

2010-09-16 Thread Alaios
I fixed by adding this:

k <- sqrt(dist(temp))
k returns sort of a list. So I need to select the first item which is the 
result.
a <- k[1]

Can someone explain me why k[1] is needed for that?

Best Regards
Alex





From: Mario Valle 

Sent: Thu, September 16, 2010 1:28:31 PM
Subject: Re: [R] help me understand how things work.

  ?dist
BTW, to me this does not happens.
x <- matrix(rnorm(100), nrow=5)
d <- dist(x)
1/sqrt(d)
1/sqrt(dist(x))

Hope it helps
 mario
On 16-Sep-10 12:02, Alaios wrote:
> Hello I have some strange output from R and I try to understand how R works.
>
> Could you please help me with that?
>
> temp<- rbind (c(10,1),c(99,98))
>> temp
>   [,1] [,2]
> [1,]   101
> [2,]   99   98
>
>
>> dist(temp)
>   1
> 2   131.6435
>
>
>> sqrt(dist(temp))
>   1
> 2   11.47360
>
> so far so good.
>
> until the nex line: when I try to do what i did before but adding the 1/(what 
I
> did before). I was expecting a number as a result of the division but
> unfortunately I took the following:
>
>   1/sqrt(dist(temp))
> [1] 0.08715662
> attr(,"Size")
> [1] 2
> attr(,"Diag")
> [1] FALSE
> attr(,"Upper")
> [1] FALSE
> attr(,"method")
> [1] "euclidean"
> attr(,"call")
> dist(x = temp)
> attr(,"class")
> [1] "dist"
>
>
> Could you please help me understand what is this about?
>
> I would like to thank you in advance for your help
> Best REgards
> Alex
>
>
>
>
> [[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.

-- 
Ing. Mario Valle
Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)  | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82


  
[[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] Interpolate? a line

2010-09-17 Thread Alaios
I would like to thank you again for your help.
But it seems that the floor function (ceiling, round too) create more dots in 
the matrix that line really "touches".

unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  ) 

You can see that in the picture below

http://yfrog.com/5blineswj

So, how to select the only the cells that the line "touches"?

I would like to thank you in advance for your help
best Regards
Alex





From: David Winsemius 

Cc: Rhelp list 
Sent: Wed, September 15, 2010 1:55:10 PM
Subject: Re: [R] Interpolate? a line


On Sep 15, 2010, at 7:24 AM, David Winsemius wrote:

> Replacing context:
> 
>>> Hello everyone.
>>> I have created a 100*100 matrix in R.
>>> Let's now say that I have a line that starts from (2,3) point and ends to 
the
>>> (62,34) point. In other words this line starts at cell (2,3) and ends at 
cell
>>> (62,34).
>>> 
>>> Is it possible to get by some R function all the matrix's cells that this 
>line
>>> transverses?
>>> 
>>> I would like to thank you for your feedback.
>>> 
>>> Best Regards
>>> Alex
> 
> On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote:
> 
>> Hello Alex,
>> 
>> Here is one way to do it. It works but it's not pretty :)
> 
> If you want an alternative, consider that produces the Y cell indices (since 
>the x cell indices are already 2:62):
> 
> > linefn <- function(x) 3+((34-3)/(62-2)) *(x-2)
> > findInterval(linefn(2:62), 3:34)
> [1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 
> 13 
>13 14
> [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 
> 27 
>27 28
> [55] 28 29 29 30 30 31 32
> # that seems "off" by two
> > linefn(62)
> [1] 34
> > linefn(2)
> [1] 3 # but that checks out and I realized those were just indices for the 
> 3:34 
>findInterval vector
> 
> > (3:34)[findInterval(linefn(2:62), 3:34)]
> [1]  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13 13 14 14 
> 15 
>15 16
> [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 
> 29 
>29 30
> [55] 30 31 31 32 32 33 34
> 
> ( no rounding and I think the logic is clearer.)

But I also realized it didn't enumerate all the the cells were crossed either, 
only indicating which cell was associated with an integer value of x. Also 
would 
have even more serious problems if the slope were greater than unity. To 
enumerate the cell indices that were crossed, try:

unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  )
  [,1] [,2]
[1,]23
[2,]33
[3,]44
[4,]54
[5,]55
[6,]65
[7,]75
[8,]76
snipping interior results
[83,]   58   32
[84,]   59   32
[85,]   60   32
[86,]   60   33
[87,]   61   33
[88,]   62   34

That could probably be passed to rect() to illustrate (and check logic):

rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col="red")

#redraw line :
lines(2:62, 3+(34-3)/(62-2)*(0:60))


> 
> --David.
> 
>> 
>> interp <- approx(c(2, 62), c(3, 34), method="linear", xout=2:62)
>> m <- matrix(c(interp$x, round(interp$y)), ncol=2)
>> tie <- m[,2] == c(-Inf, m[-nrow(m),2])
>> m <- m[ !tie, ]
>> 
>> You might want to examine the result like this...
>> 
>> plot(m)  # plots points
>> lines(c(2,26), c(3, 34))  # overlay line for comparison
> you can add a grid with
> abline(v=2:62, h=3:34)
>> 
>> Michael
>> 
>> __
>> 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.
> 
> David Winsemius, MD
> West Hartford, CT
> 
> __
> 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.

David Winsemius, MD
West Hartford, CT


  
[[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] count frequency

2010-09-17 Thread Alaios
Hello everyone,
please consider the following lines of a matrix


[574,]   59   32
[575,]   59   32
[576,]   59   32
[577,]   59   32
[578,]   59   32
[579,]   59   32
[580,]   59   32
[581,]   60   32
[582,]   60   33
[583,]   60   33
[584,]   60   33
[585,]   60   33
[586,]   60   33
[587,]   60   33
[588,]   60   33
[589,]   60   33
[590,]   60   33
[591,]   61   33
[592,]   61   33
[593,]   61   33
[594,]   61   33
[595,]   61   33
[596,]   61   33
[597,]   61   33
[598,]   61   33
[599,]   61   33
[600,]   61   33
[601,]   62   34

Is it possible somehow to count the similarities between the first and second 
column and put them on a third column like this?

59 32 3
60 33 5
62 34 1

where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)

Best Regards
Alex



  
[[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] count frequency

2010-09-17 Thread Alaios
Just to confirm,
this one worked for me

 as.data.frame(table(temp[]))
   Var1 Freq
1 1   11
2 2   29
3 3   29
4 4   29
5 5   29
6 6   29
7 7   29
8 8   29
9 9   29
10   10   29
11   11   29
12   12   29
13   13   29
14   14   29
15   15   29
16   16   29
17   17   29
18   18   30
19   19   29
20   20   29



Best Regards
Alex






From: Jorge Ivan Velez 

Cc: Rhelp 
Sent: Fri, September 17, 2010 4:24:59 PM
Subject: Re: [R] count frequency

Alaios,

Try 


as.data.frame(table(x[,1], x[,2))

where x is your matrix.

HTH,
Jorge

 


On Fri, Sep 17, 2010 at 8:19 AM, Alaios <> wrote:

Hello everyone,
>please consider the following lines of a matrix
>
>
>[574,]   59   32
>[575,]   59   32
>[576,]   59   32
>[577,]   59   32
>[578,]   59   32
>[579,]   59   32
>[580,]   59   32
>[581,]   60   32
>[582,]   60   33
>[583,]   60   33
>[584,]   60   33
>[585,]   60   33
>[586,]   60   33
>[587,]   60   33
>[588,]   60   33
>[589,]   60   33
>[590,]   60   33
>[591,]   61   33
>[592,]   61   33
>[593,]   61   33
>[594,]   61   33
>[595,]   61   33
>[596,]   61   33
>[597,]   61   33
>[598,]   61   33
>[599,]   61   33
>[600,]   61   33
>[601,]   62   34
>
>Is it possible somehow to count the similarities between the first and second
>column and put them on a third column like this?
>
>59 32 3
>60 33 5
>62 34 1
>
>where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)
>
>Best Regards
>Alex
>
>
>
>
>   [[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.
>



  
[[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] count frequency

2010-09-17 Thread Alaios
My bad :(
unfortunately does not work correct.

This is some of the output of the table
..
[494,]   50   27
[495,]   50   27
[496,]   50   27
[497,]   50   28
[498,]   50   28
[499,]   50   28
[500,]   50   28
[501,]   51   28
[502,]   51   28
[503,]   51   28
[504,]   51   28
[505,]   51   28
[506,]   51   28
[507,]   51   28
[508,]   51   28
[509,]   51   28
[510,]   51   28
[511,]   52   28
[512,]   52   28
[513,]   52   28
[514,]   52   28
[515,]   52   28
[516,]   52   29
[517,]   52   29
[518,]   52   29




I need the following results
50 27: 3
50 28: 4
51 28: 10
52 28: 5
52 29: 3


So far nothing worked.
Best Regards
Alex






From: Henrique Dallazuanna 

Cc: Rhelp 
Sent: Fri, September 17, 2010 3:09:36 PM
Subject: Re: [R] count frequency

Try this:

aggregate(rep(1, nrow(x)), x, sum)




Hello everyone,
>please consider the following lines of a matrix
>
>
>[574,]   59   32
>[575,]   59   32
>[576,]   59   32
>[577,]   59   32
>[578,]   59   32
>[579,]   59   32
>[580,]   59   32
>[581,]   60   32
>[582,]   60   33
>[583,]   60   33
>[584,]   60   33
>[585,]   60   33
>[586,]   60   33
>[587,]   60   33
>[588,]   60   33
>[589,]   60   33
>[590,]   60   33
>[591,]   61   33
>[592,]   61   33
>[593,]   61   33
>[594,]   61   33
>[595,]   61   33
>[596,]   61   33
>[597,]   61   33
>[598,]   61   33
>[599,]   61   33
>[600,]   61   33
>[601,]   62   34
>
>Is it possible somehow to count the similarities between the first and second
>column and put them on a third column like this?
>
>59 32 3
>60 33 5
>62 34 1
>
>where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)
>
>Best Regards
>Alex
>
>
>
>
>   [[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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



  
[[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] count frequency

2010-09-17 Thread Alaios
You are pretty good. 
Worked nicely :)
Thanks!

Alex





From: Henrique Dallazuanna 

Cc: Rhelp 
Sent: Fri, September 17, 2010 4:58:50 PM
Subject: Re: [R] count frequency

So try this :

aggregate(rep(1, nrow(x)), as.data.frame(x), sum)




My bad :(
>unfortunately does not work correct.
>
>This is some of the output of the table
>..
>[494,]   50   27
>[495,]   50   27
>[496,]   50   27
>[497,]   50   28
>[498,]   50   28
>[499,]   50   28
>[500,]   50   28
>[501,]   51   28
>[502,]   51   28
>[503,]   51   28
>[504,]   51   28
>[505,]   51   28
>[506,]   51   28
>[507,]   51   28
>[508,]   51   28
>[509,]   51   28
>[510,]   5128
>[511,]   52   28
>[512,]   52   28
>[513,]   52   28
>[514,]   52   28
>[515,]   52   28
>[516,]   52   29
>[517,]   52   29
>[518,]   52   29
>
>
>
>
>I need the following results
>50 27: 3
>50 28: 4
>51 28: 10
>52 28: 5
>52 29: 3
>
>
>So far nothing worked.
>Best Regards
>Alex
>
>
>
>
>

From: Henrique Dallazuanna 

>
>Cc: Rhelp 
>Sent: Fri, September 17, 2010 3:09:36 PM
>
>Subject: Re: [R] count frequency
>
>
>Try this:
>
>aggregate(rep(1, nrow(x)), x, sum)
>
>

>
>Hello everyone,
>>please consider the following lines of a matrix
>>
>>
>>[574,]   59   32
>>[575,]   59   32
>>[576,]   59   32
>>[577,]   59   32
>>[578,]   59   32
>>[579,]   59   32
>>[580,]   59   32
>>[581,]   60   32
>>[582,]   60   33
>>[583,]   60   33
>>[584,]   60   33
>>[585,]   60   33
>>[586,]   60   33
>>[587,]   60   33
>>[588,]   60   33
>>[589,]   60   33
>>[590,]   60   33
>>[591,]   61   33
>>[592,]   61   33
>>[593,]   61   33
>>[594,]   61   33
>>[595,]   61   33
>>[596,]   61   33
>>[597,]   61   33
>>[598,]   61   33
>>[599,]   61   33
>>[600,]   61   33
>>[601,]   62   34
>>
>>Is it possible somehow to count the similarities between the first and second
>>column and put them on a third column like this?
>>
>>59 32 3
>>60 33 5
>>62 34 1
>>
>>where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34)
>>
>>Best Regards
>>Alex
>>
>>
>>
>>
>>   [[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.
>>
>
>
>-- 
>Henrique Dallazuanna
>Curitiba-Paraná-Brasil
>25° 25' 40" S 49° 16' 22" O
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



  
[[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] Interpolate? a line

2010-09-21 Thread Alaios
I would like to thank you very much for making this clear. It seems that the 
solution you suggested is right one as the second attempt does find all the 
cells that are touched.
Now I ll try to find out how much the line gets into one of this cell as every 
cell affects acts like a weight. The more you are in a cell the higher the 
weight will be.

Best Regards
Alex





From: David Winsemius 

Cc: Rhelp list 
Sent: Fri, September 17, 2010 6:36:51 PM
Subject: Re: [R] Interpolate? a line


On Sep 17, 2010, at 7:22 AM, Alaios wrote:

> I would like to thank you again for your help.
> But it seems that the floor function (ceiling, round too) create more dots in 
>the matrix that line really "touches".

You said "cells" not "dots". Are you trying to change the problem now? My 
concern is rather that it can still miss cells.

> 
> unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) )  )
> 
> You can see that in the picture below
> 
> http://yfrog.com/5blineswj
> 
> So, how to select the only the cells that the line "touches"?

If you had taken my suggestion of overlaying a grid rather than plotting dots 
that fail to represent a "cell" (which I was taking to be a square of dimension 
1 x 1) you would see that my solution was correct (at least to the point of not 
missing any cells so defined that were touched up to a tolerance of 0.01 cell 
units. If you want to define "cells" differently, then it's your turn to step 
up 
and get mathematically precise. Calculus still works if you define 
neighborhoods 
as hyperspheres s  rather than epsilon by delta hyper-rectangles.

# Here is the the illustrated sequence of getting to what I am calling my 
"final 
answer",
# even though it could still miss an occasional cell.

interp <- approx(c(2, 62), c(3, 34), method="linear", xout=2:62)
m <- matrix(c(interp$x, round(interp$y)), ncol=2)
tie <- m[,2] == c(-Inf, m[-nrow(m),2])
m <- m[ !tie, ]

plot(m)  # plots points
lines(c(2,62), c(3, 34))  # overlay line for comparison
#you can add a grid with
abline(v=2:62, h=3:34)

## First attempt at integer values of x

linefn <- function(x) 3+((34-3)/(62-2)) *(x-2)
findInterval(linefn(2:62), 3:34)

# Second attempt at 0.1 intervals

#
cellidxs <- unique( floor( cbind( seq(2,62, by=0.1), # There will be many 
duplicates after rounding down
linefn(seq(2,62, by=0.1)) ) )  ) # the same function that 
just gets a y value

rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col="red")

#redraw line :
lines(2:62, 3+(34-3)/(62-2)*(0:60))
# That is the first plot with coarse tolerances
#Third attempt:
# Now calculate a set of cell ids with tolerances that at ten-fold more numerous

cellid2 <-unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62, by=0.01) )) 
) 
)
NROW(cellid2) # 91 cells
rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1, col="blue")
rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col="red")
lines(2:62, 3+(34-3)/(62-2)*(0:60))

--Best
David.

> 
> I would like to thank you in advance for your help
> best Regards
> Alex
> 
> From: David Winsemius 

> Cc: Rhelp list 
> Sent: Wed, September 15, 2010 1:55:10 PM
> Subject: Re: [R] Interpolate? a line
> 
> 
> On Sep 15, 2010, at 7:24 AM, David Winsemius wrote:
> 
> > Replacing context:
> >
> >>> Hello everyone.
> >>> I have created a 100*100 matrix in R.
> >>> Let's now say that I have a line that starts from (2,3) point and ends to 
>the
> >>> (62,34) point. In other words this line starts at cell (2,3) and ends at 
>cell
> >>> (62,34).
> >>>
> >>> Is it possible to get by some R function all the matrix's cells that this 
>line
> >>> transverses?
> >>>
> >>> I would like to thank you for your feedback.
> >>>
> >>> Best Regards
> >>> Alex
> >
> > On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote:
> >
> >> Hello Alex,
> >>
> >> Here is one way to do it. It works but it's not pretty :)
> >
> > If you want an alternative, consider that produces the Y cell indices 
> > (since 
>the x cell indices are already 2:62):
> >
> > > linefn <- function(x) 3+((34-3)/(62-2)) *(x-2)
> > > findInterval(linefn(2:62), 3:34)
> > [1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 
>13 13 14
> > [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 
> > 26 
>27 27 28
> > [55] 28 29 29 30 30 31 32
> > # that seems "off" by two
> > > linefn(62)
>

[R] Indexing sublists inside lists.

2010-09-21 Thread Alaios
I would like to thank you very much for your reply.
Actually I would like to ask you if there is 
a small list called fred:
fred <- list(happy = 1:10, name = "squash")
and a big list called bigfred that included fred list 5 times
bigfred <- rep(fred,5)

Is it possible somehow to index all these sublists(fred) inside bigfred with a 
more direct way like
bigfred[1] shows the first sublist fred
bigfred[2][2] shows the second sublist fred, the second element of the fred list

So far I found some way to do this by refering to the sublists by the following:
bigfred[1+index*length(fred)]
where index shows the beginning of a sublist.

I would like to thank you in advance for your help
Best Regards
Alex






From: David Winsemius 

Cc: Dennis Murphy ; Rhelp 
Sent: Tue, September 14, 2010 3:55:39 PM
Subject: Re: [R] Object oriented programming in R.


On Sep 14, 2010, at 9:29 AM, Alaios wrote:

> I would like to thank you very much all that you helped me so far.
> So I tried to check how the following works
> 
> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
> 
> This returns the following :
> 
>> fred[1]
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
> 
> 
>> fred[2]
> $name
> [1] "squash"

Not on my machine:

> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"


> 
> What I am trying to do is to address the number 5 of the fred[1] $happy value.
> I tried something like fred[1][5] fred[1,5]
> but it didn't work

Almost:

> fred[[1]][5]
[1] 5


> 
> I would like to thank you in advance for your help
> 
> Best Regards
> Alex
> 
> 
> From: Dennis Murphy 
> 
> Cc: Rhelp 
> Sent: Tue, September 14, 2010 3:13:37 PM
> Subject: Re: [R] Object oriented programming in R.
> 
> Hi:
> 
> You could create a list of lists, where the outer list would be between agents
> and the inner list within agents. The inner list could have the 'matrices and
> one list' as separate components for each agent. Of course, you would have to 
>be
> able to keep all of this straight :)
> 
> HTH,
> Dennis
> 
> 
> Here are some more information:
>> I would like to create some agents that span over a specific area map.Every
>> agent needs to have its own data structures like one or two matrices and one
>> list.
>> 
>> I think that the best way to do this is to create objects and every instance 
>of
>> an object will be used for a single agent.
>> 
>> The number of agents is not predetermined and it varies for any execution.
>> So I read this value from the command line interface and then I would like to
>> initiate so many objects as the agents. I think that the best way to do that 
>is
>> to create using a for loop a list containing as many objects as the agents 
>are.
>> 
>> 
>> I would like to thank you in advance for your help
>> 
>> Best Regards
>> Alex
>> 
>> 
>> From: jim holtman 
>> 
>> Cc: Tal Galili ; Rhelp 
>> Sent: Tue, September 14, 2010 1:40:37 PM
>> 
>> Subject: Re: [R] Object oriented programming in R.
>> 
>> 
>> It depends on what you mean by objects.  If you are just looking at
>> creating many named variables that are going to hold values (e.g.,
>> reading in data from several files that you want to correlate
>> separately), then consider the use of 'lists'.  Can you provide a
>> little more detail on exactly the problem that you are trying to
>> solve, and then maybe we can propose a solution.
>> 
>> 
>> 
>>> Thank you very much. I checked the tutorials that on that list but still I 
do
>>> not know how to create many objects of the same type. Can you please help me
>>> with that?
>>> 
>>> Best Regards
>>> Alex
>>> 
>>> 
>>> 
>>> 
>>> 
>>> From: Tal Galili 
>>> 
>>> Cc: Rhelp 
>>> Sent: Tue, September 14, 2010 10:11:36 AM
>>> Subject: Re: [R] Object oriented programming in R.
>>> 
>>> 
>>> Hello Alaios,
>>> I see a bunch of good materials here:
>>>http://www.google.

[R] efficient list indexing

2010-09-22 Thread Alaios
Hello everyone,

I need some help with lists inside lists (a good way to emulate a struct)\

Assume that there is a small list called fred:
fred <- list(happy = 1:10, name = "squash")


and a big list called bigfred that includes fred list 5 times
bigfred <- rep(fred,5)

Is it possible somehow to index all these sublists(fred) inside bigfred with a 
more direct way like this:
bigfred[1] shows the first sublist fred
bigfred[2][2] shows the second sublist fred, the second element of the fred list

So far I found some way to do this by refering to the sublists by the following:
bigfred[1+index*length(fred)]
where index shows the beginning of a sublist.

I would like to thank you in advance for your help
Best Regards
Alex



  
[[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] efficient list indexing

2010-09-22 Thread Alaios
Great one!
Thanks this will simplify a lot addresing.
Best REgards





From: Keith Jewell 
To: r-h...@stat.math.ethz.ch
Sent: Wed, September 22, 2010 1:25:27 PM
Subject: Re: [R] efficient list indexing

Also, it may be that you want bigfred to be a list of 5 lists each of 2 
elements (happy and name) rather than a list of 10 elements.

Thus (also using double bracketing)

fred<- list(happy = 1:10, name = "squash")
bigfred <- replicate(5, fred, FALSE)
bigfred[[2]][[2]]

hth

Keith J

"Patrick Burns"  wrote in message 
news:4c99e118.2010...@pburns.seanet.com...
> I'm confused by what you are looking for.
> There's some slight possibility that you
> are looking for double bracket subscripting
> with a vector:
>
> > list(a=1:5, b=letters)[[c(2,4)]]
> [1] "d"
>
>
> On 22/09/2010 10:58, Alaios wrote:
>> Hello everyone,
>>
>> I need some help with lists inside lists (a good way to emulate a 
>> struct)\
>>
>> Assume that there is a small list called fred:
>> fred<- list(happy = 1:10, name = "squash")
>>
>>
>> and a big list called bigfred that includes fred list 5 times
>> bigfred<- rep(fred,5)
>>
>> Is it possible somehow to index all these sublists(fred) inside bigfred 
>> with a
>> more direct way like this:
>> bigfred[1] shows the first sublist fred
>> bigfred[2][2] shows the second sublist fred, the second element of the 
>> fred list
>>
>> So far I found some way to do this by refering to the sublists by the 
>> following:
>> bigfred[1+index*length(fred)]
>> where index shows the beginning of a sublist.
>>
>> I would like to thank you in advance for your help
>> Best Regards
>> Alex
>>
>>
>>
>>
>> [[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.
>>
>
> -- 
> Patrick Burns
> pbu...@pburns.seanet.com
> http://www.burns-stat.com
> (home of 'Some hints for the R beginner'
> and 'The R Inferno')
>

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



  
[[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] efficient list indexing

2010-09-22 Thread Alaios
For some reason I did not receive your email.
Sorry for the inconvenience caused






From: Dennis Murphy 

Cc: Rhelp 
Sent: Wed, September 22, 2010 1:46:28 PM
Subject: Re: [R] efficient list indexing

Hi:

I believe we had this discussion yesterday, 
http://r.789695.n4.nabble.com/Object-oriented-programming-in-R-td2538541.html#a2538916


but since you chose to repeat that message, it clearly wasn't enough, so start 
with 


http://cran.r-project.org/doc/manuals/R-intro.html#Lists
http://stackoverflow.com/questions/2050790/how-to-correctly-use-lists-in-r

With the following example as a reference:
Empl <- list(employee = "Anna", spouse = "Fred", children = 3,
child.ages = c(4, 7, 9))

we quote Venables and Ripley (2002, p. 45):
  "It is important to appreciate the difference between [ and [[. The [ form 
extracts sub-vectors, so Empl[2] is a list of length one, whereas Empl[[2]] is 
a 
component (a character vector of length one)."

In that context, consider the following:
> Empl$employee
[1] "Anna"
> Empl$child.ages[2]
[1] 7
> x <- "spouse"; Empl[[x]]
[1] "Fred"
> Empl[[3]]
[1] 3
> Empl[[4]]
[1] 4 7 9
> Empl[[4]][2]
[1] 7
> Empl[4]
$child.ages
[1] 4 7 9
> Empl[4][2]   # Why?
$
NULL
> Empl[2]
$spouse
[1] "Fred"
> Empl[[2]]   # Why the difference?
[1] "Fred"


A somewhat more expansive discussion is found on pp. 12-13 of Venables and 
Ripley (2000), S Programming.

Dennis




Hello everyone,
>
>I need some help with lists inside lists (a good way to emulate a struct)\
>
>Assume that there is a small list called fred:
>fred <- list(happy = 1:10, name = "squash")
>
>
>and a big list called bigfred that includes fred list 5 times
>bigfred <- rep(fred,5)
>
>Is it possible somehow to index all these sublists(fred) inside bigfred with a
>more direct way like this:
>bigfred[1] shows the first sublist fred
>bigfred[2][2] shows the second sublist fred, the second element of the fred 
list
>
>So far I found some way to do this by refering to the sublists by the 
following:
>bigfred[1+index*length(fred)]
>where index shows the beginning of a sublist.
>
>I would like to thank you in advance for your help
>Best Regards
>Alex
>
>
>
>
>   [[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.
>



  
[[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] print-show-display a matrix

2010-10-04 Thread Alaios
Hello. 
I want to print the value a matrix has. The matrix's size is not too big 
(100*100 cells). I tried print(matrixname) but as it does not fit very well on 
my screen R splits it into several small matrixes that do overflow my screen.
IS it possible somehow to display this matrix as one (even if this needs to go 
fullscreen) . There might be some function for that like plot cells or display 
matrixes.

I would like to thank you in advance for your help

Best Regards
Alex


  
[[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] Make a loop more efficient

2010-10-05 Thread Alaios
Hello everyone
I need some advice if the following might be easier implemented.


There are n matrixes

each matrix needs to calculate one value for the rest n-1 matrixes (but not for 
itself). I implemented this one by 

two nested loops


for (i in c(1:length(CRX))) {

   for (j in c(1:length(CRX)))
   if (i!=j) # where i and j are the two indexes. If i==j then is the same 
matrix.
   calculations();


}


Do you think there might be a more efficient R-wise way to implement this?

I would like to thank you in advance for your help

Best Regards
Alex



  
[[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] Linear Integration

2010-10-05 Thread Alaios
Hello 
I would like to calculate a weighted line integral. 
The integral is calculated by the cells that this lines trasverses (the small 
cells belong to  matrix (m*n) that represent the value that a specific area has.

I need to calculate the weights by finding out how much the line touches or 
impinges inside a cell.
The weight is less if a line just touches one of the four edges of a square and 
much more if it traverses inside the cell. I think there might be some function 
to calculate this in any image processing packages.
So far I could not find anything appropriate. 
Could you please help me with that?

I would like to thank you in advance for your help
Best Regards
Alex



  
[[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] print-show-display a matrix

2010-10-06 Thread alaios

Just to confirm that it works. Thanks for help.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/print-show-display-a-matrix-tp2954168p2964344.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] Make a loop more efficient

2010-10-06 Thread alaios

Thank you very much both of you.
I will check and post back later if needed.

Best Regards
Alex
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Make-a-loop-more-efficient-tp2955912p2964346.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] Linear Integration

2010-10-06 Thread alaios

I would like to thank you for your reply.
Yes I had this conversation of how to find the cells that are touched.

 
I did that with these two lines:
temp<-(floor(cbind(seq(x[1],xr[1],by=0.01),lineeq(x,xr #. 
cellid2 <-unique( floor(cbind(seq(x[1],xr[1], by=0.01), lineeq(x,xr)) ) ) #
cell ids that are touched

You can find in the picture below how the cells look like for a line that
spans from (2,11) to (3,8)

http://img824.imageshack.us/img824/9914/lineu.jpg

In the picture attached you can see that there are some points missing
denoted by * which I do not know how to find out. I need them to find the
proportion a line gets into each cell. 
You mentioned something like "densified vertices of the line" but I am not
sure what does it mean.

In the picture are depicted the areas that I need to calculate somehow. Of
course the easiest way would be to use some already implemented function
which does not seem to exist.

I would like to thank everyone that contributed to this so far.
Best Regards
Alex

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Linear-Integration-tp2956145p2964694.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] Looking for a book/tutorial with the following context:

2010-10-06 Thread alaios

Hello everyone.
It is time to start writing more and more function and I want to read in a
good reference 
-book ( I can buy one, especially if it is second handed :P)
-online tutorial
-any other guide

-How functions really work in R
-How to write bigger R programs
-If there are local function variables.
-Global ones and how to treat them
-How to include function files in order to keep your all increasing code
into separate files
-How to debug an R program step by step.
-How to print debugging messages.

I would like to thank you in advance for your help

Best Regards
Alex
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Looking-for-a-book-tutorial-with-the-following-context-tp2965206p2965206.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] Linear Integration

2010-10-07 Thread alaios

No, because I thought something that might be easier.
If you see the image again you might notice that the proportions I am
looking for might also be found by using the hypotenuse which is the same
(as all squares are triangles) by finding the adjacent. The adjacent are
easier to be found by tracking when the x value changes.

This happens when the x value increments by one and when y also increments
by one. As I know the line equation y=a*x+b it is very easy all these
points.
Then it is straightforward to find the proportion of these vectors?

Best Regards
Alex
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Linear-Integration-tp2956145p2966318.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.


  1   2   3   4   5   >