Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread Philip Rhoades via R-help
avi, On 2023-06-21 12:46, avi.e.gr...@gmail.com wrote: I was rushing out Phil so let me amend what I wrote. As others noted, this is fairly beginner stuff. If you have more such questions, besides reading up, please consider sending questions to the Tutor mailing list where there is more patien

Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread avi.e.gross
I was rushing out Phil so let me amend what I wrote. As others noted, this is fairly beginner stuff. If you have more such questions, besides reading up, please consider sending questions to the Tutor mailing list where there is more patience. 😉 You wanted to change selected small values to 0.0

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Philip Rhoades via R-help
Eric, On 2023-06-21 04:02, Eric Berger wrote: Hi Philip, In the decades since you learned R there have been some additions to the language. In particular, R now supports lambda functions. Applying this feature to Ivan's beautiful solution cuts down 7 characters (continuing his golfing analogy)

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Eric Berger
Hi Philip, In the decades since you learned R there have been some additions to the language. In particular, R now supports lambda functions. Applying this feature to Ivan's beautiful solution cuts down 7 characters (continuing his golfing analogy) unlist(lapply(seq_along(x), \(i) x[i] * x[-(1:i)]

Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread Philip Rhoades via R-help
Bert, On 2023-06-21 03:31, Bert Gunter wrote: IMO: You need to do your due diligence. This list is not meant to serve as a substitute for learning the basics of R, which you have clearly not done. Please go through an R tutorial or two (there is even one that ships with R, "An Inroduction to R"

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Philip Rhoades via R-help
Ivan, On 2023-06-21 03:32, Ivan Krylov wrote: В Wed, 21 Jun 2023 03:13:52 +1000 Philip Rhoades via R-help пишет: This: !(1,2,3,4,5) would give this: (2,3,4,5, 6,8,10, 12,15, 20) Do you mean taking a product of every element of the vector with all following vector elements? A relat

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Uwe Ligges
vf <- function(x){ o <- outer(x, x) as.vector(na.omit(o[lower.tri(o)])) } vf(1:5) vf(c(1,2,NA,4,5)) Best, Uwe Ligges On 20.06.2023 19:13, Philip Rhoades via R-help wrote: People, What I mean is, is there an elegant way to do this: This:   !(1,2,3,4,5) would give this:   (2,3,4,5,

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Sarah Goslee
Well, I think this is reasonable elegant, but ymmv. Turning it into a function and removing NA values is left for you. > x <- 1:5 > unlist(sapply(seq(1, length(x) - 1), function(i){x[i] * x[seq(i + 1, > length(x))]})) [1] 2 3 4 5 6 8 10 12 15 20 > > x <- c(1, 2, NA, 4, 5) > unlist(sapply(s

Re: [R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Ivan Krylov
В Wed, 21 Jun 2023 03:13:52 +1000 Philip Rhoades via R-help пишет: > This: > >!(1,2,3,4,5) > > would give this: > >(2,3,4,5, 6,8,10, 12,15, 20) Do you mean taking a product of every element of the vector with all following vector elements? A relatively straightforward way would be (gi

Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread Bert Gunter
IMO: You need to do your due diligence. This list is not meant to serve as a substitute for learning the basics of R, which you have clearly not done. Please go through an R tutorial or two (there is even one that ships with R, "An Inroduction to R") before posting further here. There are many good

[R] OK, next Q - a sort of factorial on a vector

2023-06-20 Thread Philip Rhoades via R-help
People, What I mean is, is there an elegant way to do this: This: !(1,2,3,4,5) would give this: (2,3,4,5, 6,8,10, 12,15, 20) and this: !(1,2,NA,4,5) would give this: (2,4,5, 8,10, 20) ? Thanks! Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: p...@pricom.

Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread Philip Rhoades via R-help
avi, On 2023-06-21 01:55, avi.e.gr...@gmail.com wrote: Phil, What have you tried. This seems straightforward enough. Could you clarify what you mean by NULL? I guess in R in would just be an empty cell? - ie NOT a zero. In R, it is common to use NA or a more specific version of it. A

Re: [R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread avi.e.gross
Phil, What have you tried. This seems straightforward enough. Could you clarify what you mean by NULL? In R, it is common to use NA or a more specific version of it. So assuming you have two vectors containing floats with some NA, then: C <- A*B Will give you the products one at a time if the

[R] Multiplying two vectors of the same size to give a third vector of the same size

2023-06-20 Thread Philip Rhoades via R-help
People, I am assuming that what I want to do is easier in R than say Ruby. I want to do what the Subject says ie multiply the cells in the same position of two vectors (A and B) to give a result in the same position in a third vector (C) BUT: - The values in the cells of A and B are floats b

Re: [R] inconsistency in mclapply.....

2023-06-20 Thread akshay kulkarni
Dear Ivan, Yes, you were rightthe native BLAS version of my ubuntu system is: Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 Updating BLAS with ropenblas(), as you said,is superfi