Re: [R] Is this foreach behaviour correct?

2016-11-09 Thread James Hirschorn
Yes, I should have put

 > library(foreach)

 > library(zoo)

at the top.

On 11/06/2016 05:20 PM, Duncan Murdoch wrote:
> On 06/11/2016 5:02 PM, Jim Lemon wrote:
>> hi James,
>> I think you have to have a starting date ("origin") for as.Date to
>> convert numbers to dates.
>
> That's true with the function in the base package, but the zoo package 
> also has an as.Date() function, which defaults the origin to 
> "1970-01-01".  If James is using zoo his code would be okay. If he's 
> not, he would have got an error, so I think he must have been.
>
> Duncan Murdoch
>
>>
>> Jim
>>
>> On Sun, Nov 6, 2016 at 12:10 PM, James Hirschorn
>>  wrote:
>>> This seemed odd so I wanted to check:
>>>
>>>  > x <- foreach(i=1:10100, .combine='c') %do% { as.Date(i) }
>>>
>>> yields a numeric vector for x:
>>>
>>>  > class(x)
>>> [1] "numeric"
>>>
>>> Should it not be a vector of Date?
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Peter Langfelder
Add a

simplify = FALSE

to the call to replicate, and you'll get a list.

replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE)

Peter

On Wed, Nov 9, 2016 at 10:45 AM, Rui Barradas  wrote:
> Hello,
>
> I also thought of replicate() but it creates an 2x2x5 array, not a list.
> Maybe it's all the same for the OP.
>
> Rui Barradas
>
> Em 09-11-2016 18:41, Marc Schwartz escreveu:
>>
>>
>>> On Nov 9, 2016, at 12:32 PM, Evan Cooch  wrote:
>>>
>>> So, its easy enough to create a random matrix, using something like (say)
>>>
>>> matrix(rnorm(4),2,2)
>>>
>>> which generates a (2x2) matrix with random N(0,1) in each cell.
>>>
>>> But, what I need to be able to do is create a 'list' of such random
>>> matrices, where the length of the list (i.e., the number of said random
>>> matrices I store in the list) is some variable I can pass to the function
>>> (or loop).
>>>
>>> I tried the obvious like
>>>
>>> hold <- list()
>>> for (i in 1:5) {
>>> hold[[i]] <- matrix(rnorm(4),2,2)
>>> }
>>>
>>>
>>> While this works, it seems inelegant, and I'm wondering if there is a
>>> better (more efficient) way to accomplish the same thing -- perhaps avoiding
>>> the loop.
>>>
>>> Thanks in advance...
>>
>>
>>
>> Hi,
>>
>> See ?replicate
>>
>> Example:
>>
>> ## Create a list of 5 2x2 matrices
>>
>>> replicate(5, matrix(rnorm(4), 2, 2))
>>
>> , , 1
>>
>> [,1]  [,2]
>> [1,] -0.1695775 1.0306685
>> [2,]  0.1636667 0.1044762
>>
>> , , 2
>>
>> [,1]  [,2]
>> [1,] -0.3098566 2.1758363
>> [2,] -0.8029768 0.9697776
>>
>> , , 3
>>
>> [,1]  [,2]
>> [1,]  0.5702972 0.7165806
>> [2,] -0.9731331 0.8332827
>>
>> , , 4
>>
>> [,1]   [,2]
>> [1,] -0.8089588 0.09195256
>> [2,] -0.2026994 0.67545827
>>
>> , , 5
>>
>>[,1]   [,2]
>> [1,] 0.5093008 -0.3097362
>> [2,] 0.6467358  0.3536414
>>
>>
>> Regards,
>>
>> Marc Schwartz
>>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread Jim Lemon
Thanks - it made me realize that I had reversed the column and row selection

rowMeans(x[seq(1:dim(x)[1],by=4),-1])

Jim


On Thu, Nov 10, 2016 at 8:30 AM, Uwe Ligges
 wrote:
>
>
> On 09.11.2016 22:06, Jim Lemon wrote:
>>
>> Hi Milu,
>> Perhaps this will help:
>>
>> apply(as.matrix(x[-1,seq(1:dim(x)[1],by=4)]),1,mean)
>
>
> More efficient than apply(..., 1, mean): rowMeans()
>
> Best,
> Uwe Ligges
>
>
>
>
>>
>> Jim
>>
>>
>> On Thu, Nov 10, 2016 at 4:00 AM, Miluji Sb  wrote:
>>>
>>> Thanks a lot for your quick reply. I made a mistake in the question, I
>>> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel 
>>> wrote:
>>>
 Hi Milu,
 The following should work for an array x (provided dim(x)[2] is
 divisible
 by 4):

 colMeans(x[,0:(dim(x)[2]/4-1)*4+1])

 -Dan

 On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:

> Dear all,
>
> I have a dataset with hundreds of columns, I am only providing only 12
> columns. Is it possible to take the mean of every four (or 12) columns
>  (value601, value602, value603, value604 etc.in this case) and repeat
> for
> the hundreds of columns? Thank you.
>
> Sincerely,
>
> Milu
>
> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
> -7.11564493179321, 0.987620949745178, 13.0476207733154,
> 6.36939525604248
> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
> 2.88946437835693, 14.9204912185669, 9.42428588867188,
> -6.80674123764038,
> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
> c(22.0399188995361,
> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
> 18.3277816772461, -2.54092741012573, 10.5550804138184,
> 25.1016540527344,
> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
> c(33.9698333740234,
> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
> c(27.5402088165283,
> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
> c(9.12979793548584,
> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
> 7.55471754074097, -5.58141136169434, -0.566209673881531,
> 12.3264112472534,
> 6.65576601028442)), .Names = c("value601", "value602", "value603",
> "value604", "value605", "value606", "value607", "value608", "value609",
> "value610", "value611", "value612"), row.names = c("1", "2",
> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


 --
 Dan Dalthorp, PhD
 USGS Forest and Rangeland Ecosystem Science Center
 Forest Sciences Lab, Rm 189
 3200 SW Jefferson Way
 Corvallis, OR 97331
 ph: 541-750-0953
 ddalth...@usgs.gov


>>>
>>> [[alternative HTML version deleted]]
>>>
>>> 

Re: [R] Average every 4 columns

2016-11-09 Thread Uwe Ligges



On 09.11.2016 22:06, Jim Lemon wrote:

Hi Milu,
Perhaps this will help:

apply(as.matrix(x[-1,seq(1:dim(x)[1],by=4)]),1,mean)


More efficient than apply(..., 1, mean): rowMeans()

Best,
Uwe Ligges





Jim


On Thu, Nov 10, 2016 at 4:00 AM, Miluji Sb  wrote:

Thanks a lot for your quick reply. I made a mistake in the question, I
meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!

Sincerely,

Milu

On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel  wrote:


Hi Milu,
The following should work for an array x (provided dim(x)[2] is divisible
by 4):

colMeans(x[,0:(dim(x)[2]/4-1)*4+1])

-Dan

On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:


Dear all,

I have a dataset with hundreds of columns, I am only providing only 12
columns. Is it possible to take the mean of every four (or 12) columns
 (value601, value602, value603, value604 etc.in this case) and repeat for
the hundreds of columns? Thank you.

Sincerely,

Milu

structure(list(value601 = c(10.1738710403442, 3.54112911224365,
12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
-7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
-0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
c(22.0399188995361,
14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
c(33.9698333740234,
26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
c(27.5402088165283,
21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
5.73408317565918, 18.9752082824707, 13.572542236), value612 =
c(9.12979793548584,
2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
6.65576601028442)), .Names = c("value601", "value602", "value603",
"value604", "value605", "value606", "value607", "value608", "value609",
"value610", "value611", "value612"), row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posti
ng-guide.html
and provide commented, minimal, self-contained, reproducible code.





--
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] Average every 4 columns

2016-11-09 Thread Jim Lemon
Hi Milu,
Perhaps this will help:

apply(as.matrix(x[-1,seq(1:dim(x)[1],by=4)]),1,mean)

Jim


On Thu, Nov 10, 2016 at 4:00 AM, Miluji Sb  wrote:
> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>
> Sincerely,
>
> Milu
>
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel  wrote:
>
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>>
>> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>>
>> -Dan
>>
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>>
>>> Dear all,
>>>
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>>  (value601, value602, value603, value604 etc.in this case) and repeat for
>>> the hundreds of columns? Thank you.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 

Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Thanks, David.

It does read without error using readBin. And using file.info as you
suggest seem to be a step in the right direction (the length of foo agrees
with 'wc -l' on the file). I just get different errors on subsequent
attempts to use it.

(I should have mentioned in the beginning, whatever I do, I'd like it to
work on both Mac and Linux.)

And thanks again to all three of you. I'm about ready to give up on an R
solution, and call an external script as Marc suggests.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/9/16, 11:27 AM, "David Winsemius"  wrote:

>
>> On Nov 9, 2016, at 10:35 AM, MacQueen, Don  wrote:
>> 
>> Bob,
>> 
>> Thanks for responding. I've tried the functions in bcrypt, and get, for
>> example,
>> 
>>> infl <- 'path.to.the.encrypted.file'
>>> junk <- 'the.password'
>>> foo <- readLines(infl)
>> Warning message:
>> In readLines(infl) :
>>  incomplete final line found on 'path.to.the.encrypted.file'
>
>I would not have expected that to succeed. readLines drops cr's and lf's
>and it certainly seems possible that those characters might be encrypted
>values randomly sprinkled through the image. What happens when you read
>it as raw? (may need to first get `file.info` to determine file length.)
>
>perhaps something along the lines of
>
>foo <- readBin( infl, "raw", file.info(infl)[1, "size"])
>
>-- 
>David
>
>
>>> tmp <- checkpw(junk, foo)
>> Error in hashpw(password, hash) : Invalid salt
>> 
>> Thus demonstrating that I don't know what I'm doing.
>> 
>> If it's easy to expand, as you mention, I would indeed appreciate it.
>> 
>> -Don
>> 
>> 
>> -- 
>> Don MacQueen
>> 
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>> 
>> 
>> 
>> 
>> 
>> On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:
>> 
>>> Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>>> might be of assistance.
>>> 
>>> If not, drop a note back to the list as it'll be trivial to expand on
>>> that to give you an R alternative to Perl.
>>> 
>>> On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don 
>>>wrote:
 I have a file containing encrypted contents. The contents can be
 decrypted
 using perl, like this:
 
 open (FILEHANDLE, "/path/to/file")
 chomp ($ciphertext = );
 
 
 use Crypt::CBC;
 $cipher = Crypt::CBC->new( -key=> 'my secret key',
   -cipher => 'Blowfish'
  );
 
 $plaintext  = $cipher->decrypt($ciphertext);
 
 
 (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
 
 M goal is to have the value of $plaintext in an R object, so, is there
 an
 R equivalent to this decrypt() perl function?
 
 I've found R packages
  bcrypt
  sodium
 that appear to have potential, but I don't understand this business
well
 enough to figure out how to use them, if indeed they can be used, for
 this. Help would be much appreciated.
 
 Thanks
 -Don
 
 --
 Don MacQueen
 
 Lawrence Livermore National Laboratory
 7000 East Ave., L-627
 Livermore, CA 94550
 925-423-1062
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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
>Alameda, CA, USA
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with decrypting

2016-11-09 Thread Marc Schwartz
Hi Don,

Since there is not a current R package implementation of the blowfish algorithm 
for encyrpt/decrypt, as far as I can tell, your only options via R would be to 
call an external script/program that provides that functionality from within R, 
or consider integrating one of the compiled language versions (e.g. C/C++) into 
an R package that you would create, presuming that the licenses for those 
implementations would allow for that. The algorithm itself is public domain 
thanks to Bruce.

There are "interpreted" versions of the Blowfish implementation available, 
including one in pure Perl in the Crypt module and a Visual Basic version, 
which you could possibly follow and re-write in pure R. But going that route 
risks introducing errors in the implementation, which needless to say, is not a 
risk you really want to take.

However, in general, encrypt/decrypt algorithms are designed to be 
intentionally difficult and are usually CPU bound, since they are doing 
multiple rounds of bit-level manipulations. Thus, using interpreted program 
versions for anything but a small amount of text is typically going to be 
problematic compute time-wise.

That is why they are generally implemented in compiled languages or for more 
complex algorithms, in firmware.

BTW, vis-a-vis your reply back to Bob, as I noted, the variant of Blowfish that 
is in the bcrypt package on CRAN will not do what you want. It is designed to 
do one thing, encrypt passwords using a non-reversible algorithm (hash) for 
storage and later comparison with an entered cleartext password, that is 
encrypted using the same algorithm. 

Regards,

Marc


> On Nov 9, 2016, at 12:11 PM, MacQueen, Don  wrote:
> 
> Thanks, Marc,
> 
> Unfortunately, I didn't choose the encryption method. My (only) need is to be 
> able to decrypt an existing file that is maintained by others. I am able to 
> use system() on a simple perl script to do the job, but I'm hoping for an 
> R-only solution, primarily for portability.
> 
> -Don
> 
> -- 
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> From: Marc Schwartz >
> Date: Monday, November 7, 2016 at 3:30 PM
> To: dh m >
> Cc: R-help >
> Subject: Re: [R] Help with decrypting
> 
> 
>> On Nov 7, 2016, at 4:47 PM, MacQueen, Don > > wrote:
>> 
>> I have a file containing encrypted contents. The contents can be decrypted
>> using perl, like this:
>> 
>> open (FILEHANDLE, "/path/to/file")
>> chomp ($ciphertext = );
>> 
>> 
>> use Crypt::CBC;
>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>   -cipher => 'Blowfish'
>>  );
>> 
>> $plaintext  = $cipher->decrypt($ciphertext);
>> 
>> 
>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm 
>> )
>> 
>> M goal is to have the value of $plaintext in an R object, so, is there an
>> R equivalent to this decrypt() perl function?
>> 
>> I've found R packages
>>  bcrypt
>>  sodium
>> that appear to have potential, but I don't understand this business well
>> enough to figure out how to use them, if indeed they can be used, for
>> this. Help would be much appreciated.
>> 
>> Thanks
>> -Don
>> 
> 
> 
> 
> Hi Don,
> 
> Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
> suggested some time ago not be used. Bruce has some alternative Blowfish 
> implementations available via his web site:
> 
>   https://www.schneier.com/academic/blowfish/download.html 
> 
> 
> and there is a link there for some third party products that still have it 
> and might provide for a CLI based interface as an alternative (e.g. GnuPG) if 
> you need to use it.
> 
> From what I can tell, 'sodium' does not support Blowfish and the 
> implementation in bcrypt, if I am reading correctly, only provides for a 
> one-way hash implementation, as opposed to encrypt/decrypt functions.
> 
> Thus, barring that my searching for alternative R implementations of Blowfish 
> resulted in a Type II error, I do not see any R implementations of Blowfish 
> that support encrypt/decrypt.
> 
> If you want to use the Perl module implementation via R, you can take a look 
> at my WriteXLS package on GitHub:
> 
>   https://github.com/marcschwartz/WriteXLS 
> 
> 
> and see how I call Perl scripts within WriteXLS.R:
> 
>   https://github.com/marcschwartz/WriteXLS/blob/master/R/WriteXLS.R 
> 
> 
> around line 242.
> 
> That might provide one method for you.
> 
> That all being said, as per Bruce's recommendation, there are "better" 
> 

Re: [R] creating lists of random matrices

2016-11-09 Thread Rui Barradas

Hello,

I also thought of replicate() but it creates an 2x2x5 array, not a list.
Maybe it's all the same for the OP.

Rui Barradas

Em 09-11-2016 18:41, Marc Schwartz escreveu:



On Nov 9, 2016, at 12:32 PM, Evan Cooch  wrote:

So, its easy enough to create a random matrix, using something like (say)

matrix(rnorm(4),2,2)

which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random matrices, 
where the length of the list (i.e., the number of said random matrices I store 
in the list) is some variable I can pass to the function (or loop).

I tried the obvious like

hold <- list()
for (i in 1:5) {
hold[[i]] <- matrix(rnorm(4),2,2)
}


While this works, it seems inelegant, and I'm wondering if there is a better 
(more efficient) way to accomplish the same thing -- perhaps avoiding the loop.

Thanks in advance...



Hi,

See ?replicate

Example:

## Create a list of 5 2x2 matrices


replicate(5, matrix(rnorm(4), 2, 2))

, , 1

[,1]  [,2]
[1,] -0.1695775 1.0306685
[2,]  0.1636667 0.1044762

, , 2

[,1]  [,2]
[1,] -0.3098566 2.1758363
[2,] -0.8029768 0.9697776

, , 3

[,1]  [,2]
[1,]  0.5702972 0.7165806
[2,] -0.9731331 0.8332827

, , 4

[,1]   [,2]
[1,] -0.8089588 0.09195256
[2,] -0.2026994 0.67545827

, , 5

   [,1]   [,2]
[1,] 0.5093008 -0.3097362
[2,] 0.6467358  0.3536414


Regards,

Marc Schwartz


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Uwe Ligges
Not answering the question, but if you have the same dimensions of the 
matrices everywhere, it is much more efficient to sample all numbers in 
a row and put stuff into an array:


array(rnorm(5*4), dim=c(2,2,5)))

Best,
Uwe Ligges




On 09.11.2016 19:51, Marc Schwartz wrote:



On Nov 9, 2016, at 12:41 PM, Marc Schwartz  wrote:



On Nov 9, 2016, at 12:32 PM, Evan Cooch  wrote:

So, its easy enough to create a random matrix, using something like (say)

matrix(rnorm(4),2,2)

which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random matrices, 
where the length of the list (i.e., the number of said random matrices I store 
in the list) is some variable I can pass to the function (or loop).

I tried the obvious like

hold <- list()
for (i in 1:5) {
  hold[[i]] <- matrix(rnorm(4),2,2)
  }


While this works, it seems inelegant, and I'm wondering if there is a better 
(more efficient) way to accomplish the same thing -- perhaps avoiding the loop.

Thanks in advance...



Hi,

See ?replicate

Example:

## Create a list of 5 2x2 matrices




Sorry, correction on my reply.

I copied the wrong output, It should be:


replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE)

[[1]]
  [,1]  [,2]
[1,] 0.9700486 1.4249251
[2,] 0.7621312 0.8267747

[[2]]
  [,1]   [,2]
[1,] 0.4517927  0.2047509
[2,] 0.6336959 -0.6028124

[[3]]
  [,1]  [,2]
[1,] 0.6468823 0.4268734
[2,] 0.1664907 0.3905180

[[4]]
   [,1]   [,2]
[1,] -0.3170839 -1.0113201
[2,] -1.5356600  0.9658132

[[5]]
   [,1]   [,2]
[1,] -1.1937503 -0.2653502
[2,]  0.9319919  0.1780254


The 'simplify' argument should be FALSE, so that an array is not created.

Regards,

Marc Schwartz


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with decrypting

2016-11-09 Thread David Winsemius

> On Nov 9, 2016, at 10:35 AM, MacQueen, Don  wrote:
> 
> Bob,
> 
> Thanks for responding. I've tried the functions in bcrypt, and get, for
> example,
> 
>> infl <- 'path.to.the.encrypted.file'
>> junk <- 'the.password'
>> foo <- readLines(infl)
> Warning message:
> In readLines(infl) :
>  incomplete final line found on 'path.to.the.encrypted.file'

I would not have expected that to succeed. readLines drops cr's and lf's and it 
certainly seems possible that those characters might be encrypted values 
randomly sprinkled through the image. What happens when you read it as raw? 
(may need to first get `file.info` to determine file length.)

perhaps something along the lines of 

foo <- readBin( infl, "raw", file.info(infl)[1, "size"])

-- 
David


>> tmp <- checkpw(junk, foo)
> Error in hashpw(password, hash) : Invalid salt
> 
> Thus demonstrating that I don't know what I'm doing.
> 
> If it's easy to expand, as you mention, I would indeed appreciate it.
> 
> -Don
> 
> 
> -- 
> Don MacQueen
> 
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> 
> 
> 
> On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:
> 
>> Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>> might be of assistance.
>> 
>> If not, drop a note back to the list as it'll be trivial to expand on
>> that to give you an R alternative to Perl.
>> 
>> On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
>>> I have a file containing encrypted contents. The contents can be
>>> decrypted
>>> using perl, like this:
>>> 
>>> open (FILEHANDLE, "/path/to/file")
>>> chomp ($ciphertext = );
>>> 
>>> 
>>> use Crypt::CBC;
>>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>>   -cipher => 'Blowfish'
>>>  );
>>> 
>>> $plaintext  = $cipher->decrypt($ciphertext);
>>> 
>>> 
>>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>>> 
>>> M goal is to have the value of $plaintext in an R object, so, is there
>>> an
>>> R equivalent to this decrypt() perl function?
>>> 
>>> I've found R packages
>>>  bcrypt
>>>  sodium
>>> that appear to have potential, but I don't understand this business well
>>> enough to figure out how to use them, if indeed they can be used, for
>>> this. Help would be much appreciated.
>>> 
>>> Thanks
>>> -Don
>>> 
>>> --
>>> Don MacQueen
>>> 
>>> Lawrence Livermore National Laboratory
>>> 7000 East Ave., L-627
>>> Livermore, CA 94550
>>> 925-423-1062
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Evan Cooch

>>
>> Hi,
>>
>> See ?replicate
>>
>> Example:
>>
>> ## Create a list of 5 2x2 matrices
>
>
> Sorry, correction on my reply.
>
> I copied the wrong output, It should be:
>
> > replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE)
>


Perfect does the trick. Thanks also for the lapply solutions from 
others. The replicate approach is more 'transparent' at least to me.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Marc Schwartz

> On Nov 9, 2016, at 12:41 PM, Marc Schwartz  wrote:
> 
> 
>> On Nov 9, 2016, at 12:32 PM, Evan Cooch  wrote:
>> 
>> So, its easy enough to create a random matrix, using something like (say)
>> 
>> matrix(rnorm(4),2,2)
>> 
>> which generates a (2x2) matrix with random N(0,1) in each cell.
>> 
>> But, what I need to be able to do is create a 'list' of such random 
>> matrices, where the length of the list (i.e., the number of said random 
>> matrices I store in the list) is some variable I can pass to the function 
>> (or loop).
>> 
>> I tried the obvious like
>> 
>> hold <- list()
>> for (i in 1:5) {
>>   hold[[i]] <- matrix(rnorm(4),2,2)
>>   }
>> 
>> 
>> While this works, it seems inelegant, and I'm wondering if there is a better 
>> (more efficient) way to accomplish the same thing -- perhaps avoiding the 
>> loop.
>> 
>> Thanks in advance...
> 
> 
> Hi,
> 
> See ?replicate
> 
> Example:
> 
> ## Create a list of 5 2x2 matrices



Sorry, correction on my reply.

I copied the wrong output, It should be:

> replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE)
[[1]]
  [,1]  [,2]
[1,] 0.9700486 1.4249251
[2,] 0.7621312 0.8267747

[[2]]
  [,1]   [,2]
[1,] 0.4517927  0.2047509
[2,] 0.6336959 -0.6028124

[[3]]
  [,1]  [,2]
[1,] 0.6468823 0.4268734
[2,] 0.1664907 0.3905180

[[4]]
   [,1]   [,2]
[1,] -0.3170839 -1.0113201
[2,] -1.5356600  0.9658132

[[5]]
   [,1]   [,2]
[1,] -1.1937503 -0.2653502
[2,]  0.9319919  0.1780254


The 'simplify' argument should be FALSE, so that an array is not created.

Regards,

Marc Schwartz


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Rui Barradas

Hello,

Try using ?lapply, its return value is a list. Note however that the 
*apply functions are loops in disguise. There's nothing wrong with your 
solution to the problem, but it's true that most R users find lapply 
more elegant, like you say.


hold <- lapply(1:5, function(x) matrix(rnorm(4),2,2) )

Hope this helps,

Rui Barradas

Em 09-11-2016 18:32, Evan Cooch escreveu:

So, its easy enough to create a random matrix, using something like (say)

matrix(rnorm(4),2,2)

which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random
matrices, where the length of the list (i.e., the number of said random
matrices I store in the list) is some variable I can pass to the
function (or loop).

I tried the obvious like

hold <- list()
for (i in 1:5) {
 hold[[i]] <- matrix(rnorm(4),2,2)
 }


While this works, it seems inelegant, and I'm wondering if there is a
better (more efficient) way to accomplish the same thing -- perhaps
avoiding the loop.

Thanks in advance...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] creating lists of random matrices

2016-11-09 Thread Marc Schwartz

> On Nov 9, 2016, at 12:32 PM, Evan Cooch  wrote:
> 
> So, its easy enough to create a random matrix, using something like (say)
> 
> matrix(rnorm(4),2,2)
> 
> which generates a (2x2) matrix with random N(0,1) in each cell.
> 
> But, what I need to be able to do is create a 'list' of such random matrices, 
> where the length of the list (i.e., the number of said random matrices I 
> store in the list) is some variable I can pass to the function (or loop).
> 
> I tried the obvious like
> 
> hold <- list()
> for (i in 1:5) {
>hold[[i]] <- matrix(rnorm(4),2,2)
>}
> 
> 
> While this works, it seems inelegant, and I'm wondering if there is a better 
> (more efficient) way to accomplish the same thing -- perhaps avoiding the 
> loop.
> 
> Thanks in advance...


Hi,

See ?replicate

Example:

## Create a list of 5 2x2 matrices

> replicate(5, matrix(rnorm(4), 2, 2))
, , 1

   [,1]  [,2]
[1,] -0.1695775 1.0306685
[2,]  0.1636667 0.1044762

, , 2

   [,1]  [,2]
[1,] -0.3098566 2.1758363
[2,] -0.8029768 0.9697776

, , 3

   [,1]  [,2]
[1,]  0.5702972 0.7165806
[2,] -0.9731331 0.8332827

, , 4

   [,1]   [,2]
[1,] -0.8089588 0.09195256
[2,] -0.2026994 0.67545827

, , 5

  [,1]   [,2]
[1,] 0.5093008 -0.3097362
[2,] 0.6467358  0.3536414


Regards,

Marc Schwartz


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 lists of random matrices

2016-11-09 Thread Evan Cooch

So, its easy enough to create a random matrix, using something like (say)

matrix(rnorm(4),2,2)

which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random 
matrices, where the length of the list (i.e., the number of said random 
matrices I store in the list) is some variable I can pass to the 
function (or loop).


I tried the obvious like

hold <- list()
for (i in 1:5) {
hold[[i]] <- matrix(rnorm(4),2,2)
}


While this works, it seems inelegant, and I'm wondering if there is a 
better (more efficient) way to accomplish the same thing -- perhaps 
avoiding the loop.


Thanks in advance...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Bob,

Thanks for responding. I've tried the functions in bcrypt, and get, for
example,

> infl <- 'path.to.the.encrypted.file'
> junk <- 'the.password'
> foo <- readLines(infl)
Warning message:
In readLines(infl) :
  incomplete final line found on 'path.to.the.encrypted.file'
> tmp <- checkpw(junk, foo)
Error in hashpw(password, hash) : Invalid salt

Thus demonstrating that I don't know what I'm doing.

If it's easy to expand, as you mention, I would indeed appreciate it.

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:

>Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>might be of assistance.
>
>If not, drop a note back to the list as it'll be trivial to expand on
>that to give you an R alternative to Perl.
>
>On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
>> I have a file containing encrypted contents. The contents can be
>>decrypted
>> using perl, like this:
>>
>> open (FILEHANDLE, "/path/to/file")
>> chomp ($ciphertext = );
>>
>>
>> use Crypt::CBC;
>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>-cipher => 'Blowfish'
>>   );
>>
>> $plaintext  = $cipher->decrypt($ciphertext);
>>
>>
>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>>
>> M goal is to have the value of $plaintext in an R object, so, is there
>>an
>> R equivalent to this decrypt() perl function?
>>
>> I've found R packages
>>   bcrypt
>>   sodium
>> that appear to have potential, but I don't understand this business well
>> enough to figure out how to use them, if indeed they can be used, for
>> this. Help would be much appreciated.
>>
>> Thanks
>> -Don
>>
>> --
>> Don MacQueen
>>
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Thanks, Marc,

Unfortunately, I didn't choose the encryption method. My (only) need is to be 
able to decrypt an existing file that is maintained by others. I am able to use 
system() on a simple perl script to do the job, but I'm hoping for an R-only 
solution, primarily for portability.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


From: Marc Schwartz >
Date: Monday, November 7, 2016 at 3:30 PM
To: dh m >
Cc: R-help >
Subject: Re: [R] Help with decrypting


On Nov 7, 2016, at 4:47 PM, MacQueen, Don 
> wrote:

I have a file containing encrypted contents. The contents can be decrypted
using perl, like this:

open (FILEHANDLE, "/path/to/file")
chomp ($ciphertext = );


use Crypt::CBC;
$cipher = Crypt::CBC->new( -key=> 'my secret key',
  -cipher => 'Blowfish'
 );

$plaintext  = $cipher->decrypt($ciphertext);


(See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)

M goal is to have the value of $plaintext in an R object, so, is there an
R equivalent to this decrypt() perl function?

I've found R packages
 bcrypt
 sodium
that appear to have potential, but I don't understand this business well
enough to figure out how to use them, if indeed they can be used, for
this. Help would be much appreciated.

Thanks
-Don



Hi Don,

Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
suggested some time ago not be used. Bruce has some alternative Blowfish 
implementations available via his web site:

  https://www.schneier.com/academic/blowfish/download.html

and there is a link there for some third party products that still have it and 
might provide for a CLI based interface as an alternative (e.g. GnuPG) if you 
need to use it.

>From what I can tell, 'sodium' does not support Blowfish and the 
>implementation in bcrypt, if I am reading correctly, only provides for a 
>one-way hash implementation, as opposed to encrypt/decrypt functions.

Thus, barring that my searching for alternative R implementations of Blowfish 
resulted in a Type II error, I do not see any R implementations of Blowfish 
that support encrypt/decrypt.

If you want to use the Perl module implementation via R, you can take a look at 
my WriteXLS package on GitHub:

  https://github.com/marcschwartz/WriteXLS

and see how I call Perl scripts within WriteXLS.R:

  https://github.com/marcschwartz/WriteXLS/blob/master/R/WriteXLS.R

around line 242.

That might provide one method for you.

That all being said, as per Bruce's recommendation, there are "better" 
encryption/decryption algorithms these days (some in the 'digest' package by 
Dirk), depending upon who you are trying to protect the data from... :-)

Regards,

Marc Schwartz



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread David Winsemius

> On Nov 9, 2016, at 9:24 AM, David Winsemius  wrote:
> 
> 
>> On Nov 9, 2016, at 9:00 AM, Miluji Sb  wrote:
>> 
>> Thanks a lot for your quick reply. I made a mistake in the question, I
>> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
> 
> Then try matrix( sapply( split( x , 0:(dim(x)[2]/4-1)*4+1] ), mean) 
> 
> Again assuming that dim(x)[1] is evenly divisible by 4. (It's not clear if 
> you wanted these means "within columns" or "blocks defined by rows". This is 
> lightly tested but should provide the latter. 
> 
> sapply( split ( unlist(x) , 0:(dim(x)[2]/4-1)*4+1 ), mean)
>   159 
> 19.44819 19.22003 19.12812 

I failed to understand Daniel's logic an blindly copied his sequence which was 
not what I thought it would produce. 

Your request for "every 4" seems problematic in that your example has 10 rows 
and you haven't said what to do with the "bottom" 2 rows.

-- 
David
> 
>> 
>> Sincerely,
>> 
>> Milu
>> 
>> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel  wrote:
>> 
>>> Hi Milu,
>>> The following should work for an array x (provided dim(x)[2] is divisible
>>> by 4):
>>> 
>>> colMeans(x[,
>>> 
>>> -Dan
>>> 
>>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>>> 
 Dear all,
 
 I have a dataset with hundreds of columns, I am only providing only 12
 columns. Is it possible to take the mean of every four (or 12) columns
 (value601, value602, value603, value604 etc.in this case) and repeat for
 the hundreds of columns? Thank you.
 
 Sincerely,
 
 Milu
 
 structure(list(value601 = c(10.1738710403442, 3.54112911224365,
 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
 -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
 ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
 -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
 c(22.0399188995361,
 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
 ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
 c(33.9698333740234,
 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
 ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
 c(27.5402088165283,
 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
 ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
 c(9.12979793548584,
 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
 6.65576601028442)), .Names = c("value601", "value602", "value603",
 "value604", "value605", "value606", "value607", "value608", "value609",
 "value610", "value611", "value612"), row.names = c("1", "2",
 "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posti
 ng-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
>>> 
>>> 
>>> --
>>> Dan Dalthorp, PhD
>>> USGS Forest and Rangeland Ecosystem Science Center
>>> Forest Sciences Lab, Rm 189
>>> 3200 

Re: [R] prcomp() on correlation matrix

2016-11-09 Thread David L Carlson
I was assuming you had the data in my earlier reply. You could also look at the 
covmat= argument in princomp():

# Create some random data
> set.seed(42)
> dat <- mapply(rnorm, n=rep(100, 5), mean=(1:5)*5, sd=1:5)
# Construct covariance and correlation matrices
> dat.cov <- cov(dat)
> dat.cor <- cor(dat)
# Covariance matrix
> dat.cov.pca <- princomp(covmat=dat.cov)
> dat.cov.pca$loadings

Loadings:
 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
[1,]  0.997
[2,]  -0.994   
[3,] 0.269 -0.958  
[4,] -0.220 -0.941 -0.253  
[5,] -0.973  0.200 

   Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
SS loadings   1.01.01.01.01.0
Proportion Var0.20.20.20.20.2
Cumulative Var0.20.40.60.81.0
# Correlation matrix
> dat.cor.pca <- princomp(covmat=dat.cor)
> dat.cor.pca$loadings

Loadings:
 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
[1,] -0.453 -0.486  0.234  0.619  0.348
[2,]  0.262 -0.193  0.851-0.409
[3,]  0.279  0.691  0.313  0.374  0.455
[4,] -0.559  0.159  0.351 -0.629  0.377
[5,] -0.579  0.472 0.281 -0.602

   Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
SS loadings   1.01.01.01.01.0
Proportion Var0.20.20.20.20.2
Cumulative Var0.20.40.60.81.0

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
Sent: Wednesday, November 9, 2016 10:58 AM
To: T.Riedle
Cc: R-help@r-project.org
Subject: Re: [R] prcomp() on correlation matrix

Well, it seems you can't -- prcomp() seems to want the data matrix.

But it would be trivial using svd() -- or possibly even eigen() -- if
you understand the underlying linear algebra.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Nov 9, 2016 at 4:45 AM, T.Riedle  wrote:
> Dear R users,
>
> I am trying to do a Principal Components Analysis using the prcomp() function 
> based on the correlation matrix. How can I determine to calculate PCA on a 
> correlation or covariance matrix using prcomp()?
>
>
> Thanks in advance.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread David Winsemius

> On Nov 9, 2016, at 9:00 AM, Miluji Sb  wrote:
> 
> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!

Then try matrix( sapply( split( x , 0:(dim(x)[2]/4-1)*4+1] ), mean) 

Again assuming that dim(x)[1] is evenly divisible by 4. (It's not clear if you 
wanted these means "within columns" or "blocks defined by rows". This is 
lightly tested but should provide the latter. 

sapply( split ( unlist(x) , 0:(dim(x)[2]/4-1)*4+1 ), mean)
   159 
19.44819 19.22003 19.12812 

> 
> Sincerely,
> 
> Milu
> 
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel  wrote:
> 
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>> 
>> colMeans(x[,
>> 
>> -Dan
>> 
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>> 
>>> Dear all,
>>> 
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>> (value601, value602, value603, value604 etc.in this case) and repeat for
>>> the hundreds of columns? Thank you.
>>> 
>>> Sincerely,
>>> 
>>> Milu
>>> 
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>> 
>>>[[alternative HTML version deleted]]
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> 
>> 
>> 
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>> 
>> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 

Re: [R] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
Better is...

rowMeans(x[0:((dim(x)[1]-1)/4)*4+1, ])

On Wed, Nov 9, 2016 at 9:00 AM, Miluji Sb  wrote:

> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>
> Sincerely,
>
> Milu
>
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel 
> wrote:
>
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>>
>> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>>
>> -Dan
>>
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>>
>>> Dear all,
>>>
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>>  (value601, value602, value603, value604 etc.in this case) and repeat
>>> for
>>> the hundreds of columns? Thank you.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531,
>>> 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
rowMeans(x[0:(dim(x)[1]/4-1)*4+1, ])

On Wed, Nov 9, 2016 at 9:00 AM, Miluji Sb  wrote:

> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>
> Sincerely,
>
> Milu
>
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel 
> wrote:
>
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>>
>> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>>
>> -Dan
>>
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>>
>>> Dear all,
>>>
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>>  (value601, value602, value603, value604 etc.in this case) and repeat
>>> for
>>> the hundreds of columns? Thank you.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531,
>>> 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] prcomp() on correlation matrix

2016-11-09 Thread David L Carlson
Have you read the manual page for prcomp()?

?prcomp

Look at the examples, particularly the use of the scale.= argument.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of T.Riedle
Sent: Wednesday, November 9, 2016 6:46 AM
To: R-help@r-project.org
Subject: [R] prcomp() on correlation matrix

Dear R users,

I am trying to do a Principal Components Analysis using the prcomp() function 
based on the correlation matrix. How can I determine to calculate PCA on a 
correlation or covariance matrix using prcomp()?


Thanks in advance.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] prcomp() on correlation matrix

2016-11-09 Thread Bert Gunter
Well, it seems you can't -- prcomp() seems to want the data matrix.

But it would be trivial using svd() -- or possibly even eigen() -- if
you understand the underlying linear algebra.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Nov 9, 2016 at 4:45 AM, T.Riedle  wrote:
> Dear R users,
>
> I am trying to do a Principal Components Analysis using the prcomp() function 
> based on the correlation matrix. How can I determine to calculate PCA on a 
> correlation or covariance matrix using prcomp()?
>
>
> Thanks in advance.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread Miluji Sb
Thanks a lot for your quick reply. I made a mistake in the question, I
meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!

Sincerely,

Milu

On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel  wrote:

> Hi Milu,
> The following should work for an array x (provided dim(x)[2] is divisible
> by 4):
>
> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>
> -Dan
>
> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:
>
>> Dear all,
>>
>> I have a dataset with hundreds of columns, I am only providing only 12
>> columns. Is it possible to take the mean of every four (or 12) columns
>>  (value601, value602, value603, value604 etc.in this case) and repeat for
>> the hundreds of columns? Thank you.
>>
>> Sincerely,
>>
>> Milu
>>
>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>> c(22.0399188995361,
>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>> c(33.9698333740234,
>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>> c(27.5402088165283,
>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>> c(9.12979793548584,
>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>> "value604", "value605", "value606", "value607", "value608", "value609",
>> "value610", "value611", "value612"), row.names = c("1", "2",
>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
Hi Milu,
The following should work for an array x (provided dim(x)[2] is divisible
by 4):

colMeans(x[,0:(dim(x)[2]/4-1)*4+1])

-Dan

On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:

> Dear all,
>
> I have a dataset with hundreds of columns, I am only providing only 12
> columns. Is it possible to take the mean of every four (or 12) columns
>  (value601, value602, value603, value604 etc.in this case) and repeat for
> the hundreds of columns? Thank you.
>
> Sincerely,
>
> Milu
>
> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
> c(22.0399188995361,
> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
> c(33.9698333740234,
> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
> c(27.5402088165283,
> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
> c(9.12979793548584,
> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
> 6.65576601028442)), .Names = c("value601", "value602", "value603",
> "value604", "value605", "value606", "value607", "value608", "value609",
> "value610", "value611", "value612"), row.names = c("1", "2",
> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Average every 4 columns

2016-11-09 Thread Miluji Sb
Dear all,

I have a dataset with hundreds of columns, I am only providing only 12
columns. Is it possible to take the mean of every four (or 12) columns
 (value601, value602, value603, value604 etc.in this case) and repeat for
the hundreds of columns? Thank you.

Sincerely,

Milu

structure(list(value601 = c(10.1738710403442, 3.54112911224365,
12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
-7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
-0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
c(22.0399188995361,
14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
c(33.9698333740234,
26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
c(27.5402088165283,
21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
5.73408317565918, 18.9752082824707, 13.572542236), value612 =
c(9.12979793548584,
2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
6.65576601028442)), .Names = c("value601", "value602", "value603",
"value604", "value605", "value606", "value607", "value608", "value609",
"value610", "value611", "value612"), row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] PDE Solver and Modeling with R

2016-11-09 Thread Bert Gunter
Please learn to use the R ecosystem -- or web search (e.g.
"differential equations in R")  -- both of which would have led you
to:

https://cran.r-project.org/web/views/DifferentialEquations.html


-- Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Nov 9, 2016 at 3:24 AM, BARLAS Marios 247554
 wrote:
>
> Hello every1,
>
> Could you please suggest a good package (if any) for solving PDEs using FEMs 
> approach in R ?
>
> I'm building a model where I need to solve Poisson, heat transport eq ( 
> linear + heatsource in 2D or 3D in cylindrical Coords ) and combine the 
> results through a semi analytical model.
>
> Otherwise, do you think I can plug into the old FORTRAN libraries like SLATEC 
> ?
>
> I've never used R for this type of modeling so far, any advice on where to 
> start from is more than welcome!
>
> Thank you in advance,
>
> Marios Barlas
> PhD Candidate
> CMOS & Memory Integration
> Advanced Memory Group
>
> Leti, technology research institute
> Commissariat à l'énergie atomique et aux énergies alternatives
> T. +33 4 38 78 11 50 M. +33 6 02 61 83 49
> www.leti.fr  | Leti is a member of the Carnot Institutes network
>
>
>
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] ggplot

2016-11-09 Thread greg holly
Dear all;

I can not get legend position at the top when using the following code. It
does give at the right.


Your help is greatly appreciated.

p3 <- ggplot(a,

 aes(x = SUPER.PATHWAY,  y = SI)) +

#theme_classic()

theme_classic(legend.position="top",  axis.text=element_text(size = 16))

(p4 <- p3 + geom_point(aes(color = SUPER.PATHWAY),

   alpha = 1,

   size = 2.5,

   position = position_jitter(width = 1, height = 0.5)))

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] prcomp() on correlation matrix

2016-11-09 Thread T.Riedle
Dear R users,

I am trying to do a Principal Components Analysis using the prcomp() function 
based on the correlation matrix. How can I determine to calculate PCA on a 
correlation or covariance matrix using prcomp()?


Thanks in advance.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Alternative to apply in base R

2016-11-09 Thread Doran, Harold
The speed enhancement using your f2() is remarkable when compared to the 
apply() method I implemented. In the larger context of my actual problem, this 
essentially now solves the big computational hog and I can do some real work in 
a meaningful timeframe as a result.

Thank you for all the suggestions to those on this thread.



From: William Dunlap [mailto:wdun...@tibco.com]
Sent: Tuesday, November 08, 2016 5:14 PM
To: Doran, Harold 
Cc: peter dalgaard ; r-help@r-project.org; Fox, John 

Subject: Re: [R] Alternative to apply in base R

The version which allows any number of columns does not take
much more time than the one that requires exactly 7 columns.
If you have a zillion columns then these are not so good.

> f1 <- function(x) x[,1]*x[,2]*x[,3]*x[,4]*x[,5]*x[,6]*x[,7]
> f2 <- function(x) {
+val <- rep(1, nrow(x))
+for(i in seq_len(ncol(x))) {
+   val <- val * x[,i]
+}
+val
+ }
> z <- matrix(runif(10e6 * 7), ncol=7)
> system.time(v1 <- f1(z))
   user  system elapsed
  0.686   0.140   0.826
> system.time(v2 <- f2(z))
   user  system elapsed
  0.663   0.196   0.860
> all.equal(v1,v2,tolerance=0)
[1] TRUE

You might speed up f2 a tad by special-casing the ncol==0,
ncol==1, and ncol>1 cases.

The versions that call prod() nrow(x) times take about 25 seconds
on this machine and dataset.



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Nov 8, 2016 at 1:58 PM, Doran, Harold 
> wrote:
Well, I wish R-help had a “like” button as I would most certainly like
this reply :)

As usual, you’re right. I should have added a disclaimer that “in this
instance” there are 7 columns as the function I wrote evaluates an
N-dimensional integral and so as the dimensions change, so do the number
of columns in this matrix (plus another factor). But the number of columns
is never all that large.



On 11/8/16, 4:37 PM, "peter dalgaard" 
> wrote:

>
>> On 08 Nov 2016, at 21:23 , Doran, Harold 
>> > wrote:
>>
>> It¹s a good suggestion. Multiplication in this case is over 7 columns in
>> the data, but the number of rows is millions. Unfortunately, the values
>> are negative as these are actually gauss-quad nodes used to evaluate a
>> multidimensional integral.
>
>If there really are only 7 cols, then there's also the blindingly obvious
>
>mm[,1]*mm[,2]*mm[,3]*mm[,4]*mm[,5]*mm[,6]*mm[,7]
>
>-pd
>
>
>>
>> colSums is better than something like apply(dat, 2, sum); I was hoping
>> there was something similar to colSums/rowSums using prod().
>>
>> On 11/8/16, 3:00 PM, "Fox, John" > 
>> wrote:
>>
>>> Dear Harold,
>>>
>>> If the actual data with which you're dealing are non-negative, you
>>>could
>>> log all the values, and use colSums() on the logs. That might also have
>>> the advantage of greater numerical accuracy than multiplying millions
>>>of
>>> numbers. Depending on the numbers, the products may be too large or
>>>small
>>> to be represented. Of course, logs won't work with your toy example,
>>> where rnorm() will generate values that are both negative and positive.
>>>
>>> I hope this helps,
>>> John
>>> -
>>> John Fox, Professor
>>> McMaster University
>>> Hamilton, Ontario
>>> Canada L8S 4M4
>>> web: socserv.mcmaster.ca/jfox
>>>
>>>
>>> 
>>> From: R-help 
>>> [r-help-boun...@r-project.org] on 
>>> behalf of Doran, Harold
>>> [hdo...@air.org]
>>> Sent: November 8, 2016 10:57 AM
>>> To: r-help@r-project.org
>>> Subject: [R] Alternative to apply in base R
>>>
>>> Without reaching out to another package in R, I wonder what the best
>>>way
>>> is to speed enhance the following toy example? Over the years I have
>>> become very comfortable with the family of apply functions and
>>>generally
>>> not good at finding an improvement for speed.
>>>
>>> This toy example is small, but my real data has many millions of rows
>>>and
>>> the same operations is repeated many times and so finding a less
>>> expensive alternative would be helpful.
>>>
>>> mm <- matrix(rnorm(100), ncol = 10)
>>> rn <- apply(mm, 1, prod)
>>>
>>>   [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To 
>>> UNSUBSCRIBE and more, see
>>> 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@r-project.org mailing list -- To 
>> UNSUBSCRIBE and more, see
>> 

[R] PDE Solver and Modeling with R

2016-11-09 Thread BARLAS Marios 247554

Hello every1,

Could you please suggest a good package (if any) for solving PDEs using FEMs 
approach in R ? 

I'm building a model where I need to solve Poisson, heat transport eq ( linear 
+ heatsource in 2D or 3D in cylindrical Coords ) and combine the results 
through a semi analytical model. 

Otherwise, do you think I can plug into the old FORTRAN libraries like SLATEC ? 

I've never used R for this type of modeling so far, any advice on where to 
start from is more than welcome! 

Thank you in advance,

Marios Barlas
PhD Candidate
CMOS & Memory Integration
Advanced Memory Group

Leti, technology research institute 
Commissariat à l'énergie atomique et aux énergies alternatives
T. +33 4 38 78 11 50 M. +33 6 02 61 83 49
www.leti.fr  | Leti is a member of the Carnot Institutes network



  
  

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Spatial & Temporal Analysis of Daily Rainfall, Temperature Data

2016-11-09 Thread Bert Gunter
There are many good R tutorials on the web. Some are listed here:
https://www.rstudio.com/online-learning/#R

But you can search around for others.

If you are unable or unwilling to put in the time and effort to learn
R, there's not much we can do.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Nov 8, 2016 at 10:04 PM, Henry Utila  wrote:
> Dear R experts,
> I have a problem which I don't seem to get to pass. I want to analyze daily
> rainfall & temperature data with a lot of missing or unavailable points. I
> have been asked to use evd, evir, ismev and geoR packages. I have not used R
> before neither do I know any computer languages let alone programming.
> I was asked to put my data in excel spreadsheet then convert it into tab
> delimited or txt format. The problem am having is importing it into R. it
> says factors are not numeric or something like that with a lot of warnings.
> Would someone kindly advise how I can solve this problem, please.
> Looking forward to your support as R experts.
> Thanks.
> Henry Utila
> MALAWI
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer
> Graves
> Sent: Tuesday, 8 November, 2016 2:24 PM
> To: r-help@r-project.org
> Subject: Re: [R] a book recommendation, please [O/T]
>
>Have you considered Box and Draper (2007) Response Surfaces,
> Mixtures, and Ridge Analyses, 2nd Edition?
>
>
>You probably know that George Box invented the field of Response
> Surfaces with  Box, G. E. P. and Wilson, K.B. (1951) On the Experimental
> Attainment of Optimum Conditions (with discussion). Journal of the Royal
> Statistical Society Series B13(1):1-45.
>
>
>This book describes how to design experiments to get the data to
> optimize a physical process.  I haven't been teaching in academia for
> the past 25 years, but I taught an advanced course from the first
> edition of this book when I did.
>
>
>Still, any title "with R" sounds like it's worth reviewing and
> maybe using.
>
>
> Spencer Graves
>
>
> On 11/8/2016 12:36 AM, Erin Hodgess wrote:
>> I like BH^2 as well as a reference book!  I actually think I will go with
>> the DOE with R by Larson.  Thanks to all for the help!
>>
>> Sincerely,
>> Erin
>>
>>
>> On Mon, Nov 7, 2016 at 10:59 PM, Bert Gunter 
> wrote:
>>
>>> Have you looked here:
>>>
>>> https://www.amazon.com/s/ref=sr_pg_2?rh=n%3A283155%2Ck%
>>> 3Aexperimental+design=2=experimental+design&
>>> ie=UTF8=1478580868
>>>
>>> I would think your choice depends strongly on the arena of application.
>>>
>>> Of course I like BH^2, but that was because I was taught by them.
>>>
>>> Cheers,
>>> Bert
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming along
>>> and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Mon, Nov 7, 2016 at 8:13 PM, Erin Hodgess 
>>> wrote:
 Hello!

 Could someone recommend a good book on Design of Experiments for a
>>> Master's
 in Data Analytics, please?

 I use Montgomery's book for my undergrad course, but was thinking about
 something a little more advanced for this one.

 Any help much appreciated, particularly with R-related texts.

 Sincerely,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Mathematical and Statistics
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

  [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Spatial & Temporal Analysis of Daily Rainfall, Temperature Data

2016-11-09 Thread Jim Lemon
Geez, I must be too excited. I meant:

stringsAsFactors=FALSE

Jim

On Wed, Nov 9, 2016 at 7:44 PM, Jim Lemon  wrote:
> Hi Henry,
> You are certainly starting from the beginning. first, when you import
> the data from a CSV file, remember to add:
>
> read.csv(...,stringsAsFactors=TRUE)
>
> There will doubtless be other problems, but you have to start somewhere.
>
> Jim

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Spatial & Temporal Analysis of Daily Rainfall, Temperature Data

2016-11-09 Thread Jim Lemon
Hi Henry,
You are certainly starting from the beginning. first, when you import
the data from a CSV file, remember to add:

read.csv(...,stringsAsFactors=TRUE)

There will doubtless be other problems, but you have to start somewhere.

Jim

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.