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

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

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

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.

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! > > Sin

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, whatev

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 lang

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 (

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, a

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) : > incompl

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 fro

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

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)

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 m

[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 ra

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,

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

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(

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 <- c

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]

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

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, Dal

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&M University College Station, TX 77840-4352 -Original Message- From: R-help

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 th

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 di

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 t

[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(va

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 stic

[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

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

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 sugge

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

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 ha

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 wi

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-pro