Displaying 20 results from an estimated 72 matches for "elementwise".
Did you mean:
elementsize
2010 May 08
1
matrix cross product in R different from cross product in Matlab
...13 18
[2,] 13 20 27
[3,] 18 27 36
because there are only sums involved, however, I cant work out ALL of
them for the 3D example, something like
[,1] [,2] [,3]
[1,] 1*4+4*1 ? ? # #sum
of elementwise multiplication of first column of first matrix with first
column of second matrix of second matrix
[2,] ? 2*5+5*2 ?
? cant figure out how these were derived, definitely this is NOT
identical to e.g. http://en.wikipedia.org/wiki/Cross_product
I can work it out...
2000 Mar 20
1
Elementwise c() for lists
I have two lists of equal lengths. Each one consists of vectors. Is
there an elegant way to combine them elementwise? Elegant means: without
loops.
For instance, for
> jja_list(1:3,4:7)
> jjb_list(rep(0,4),(2,5))
I would like to get:
> list(c(1:3,rep(0,4)),c(4:7,rep(2,5))).
--- D.Trenkler ---
************************************************************************
*********
Dietrich Trenkle...
2007 Jun 28
3
applying max elementwise to two vectors
All,
Is there one liner way to obtain the max per observation for two
vectors?
I looked at apply and lapply but it seems that groundwork would have to
be done before applying either of those. The code below does it but
seems
like overkill.
Thanks!
Dave
x = rnorm(10)
y = rnorm(10)
ind = which(x < y)
z = x
z[ind] <- y[ind] ## z now contains the max's
2004 Oct 18
2
concatenating lists elementwise
Hi
How do I concatenate two lists element-by-element?
Example:
list.1 <- list(temperature=c("hot","cold") , size=c("big","medium"))
list.2 <- list(temperature=c("lukewarm") , size=c("massive","tiny"))
list.wanted <- list(temperature=c("hot","cold","lukewarm") ,
2007 Nov 21
2
matrix elementwise average with NA's
Hello fellow R users,
I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example
mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T)
mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T)
I'd like to compute the element-wise average for non-NA entries. Of course
(mat1+mat2)/2
2012 Sep 14
4
concatenating two vectors
Dear all,
I want to concatenate the elements of two vectors such as
a<-c("a1","a2")
b<-c("b1","b2")
and obtain
"a1b1", "a1b2","a2b1","a2b2"
I tried the paste and paste0 functions, but they yielded elementwise
concatenation such as
"a1b1","a2b2"
I am wondering that is there an efficient way of doing my wish, for instance
without using for loop etc.
Best
Ozgur
--
View this message in context: http://r.789695.n4.nabble.com/concatenating-two-vectors-tp4643139.html
Sent from the R...
2008 Nov 12
2
Outer, kronecker, etc.
`outer` (and related functions like kronecker) require that their
functional argument operate elementwise on arrays. This means for
example that
outer( 1:2, 3:4, list)
or
outer(1:2,3:4,function(a,b){1})
gives an error.
Is there a version of `outer`/`kronecker`/etc. that takes arbitrary
functions and does its own elementwise mapping? In the first example
above, I'd expect the result...
2011 Feb 07
1
Unusual slowing of R matrix multiplication version 2.12.1 (2010-10-15) vs 2.12.0
...ipt:
Using Version 2.12.0 on a dual core dual processor Mac:
> source("http://www.bio.umass.edu/biology/kunkel/pub/R/CuriousResult.R")
matrix multiplication 43.543 1.308 14.788
tcrossprod 41.147 1.286 11.9
transposition and reuse 40.407 3.525 43.606
elementwise after reshape 21.474 1.828 23.124
columnwise sapply 34.695 32.35 66.592
for loop over columns 37.237 29.471 67.2
On the same day upgrading to 2.12.1 on the same dual core dual processor Mac:
> source("http://www.bio.umass.edu/biology/kunkel/pub/R/CuriousResult.R&...
2000 Sep 26
1
Permutations
Hi,
this is maybe not a real R problem but I want to solve this in R ;-)
Consider the set of all permutations of 1:N (=: S, say) and a fixed
element a from S. I now need to compute the number of permutations s from
S which are elementwise less or equal to a: | { s \in S | s <= a } |
Of cource, backtracking using a tree structure is possible. Does anyone
know an efficient way?
Torsten
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/...
2007 Dec 04
2
Wishlist: mention Vectorize in 'outer' man page (PR#10490)
...linux
Submission from: (NULL) (213.140.16.187)
In 'outer' man page, there is no mention of the Vectorize function.
Moreover, I think it isn't underlined enough that the FUN argument to 'outer'
must be a vectorized function (doc speaks about a function which has to 'operate
elementwise').
A cross-reference from outer to Vectorize (which already has 'outer' usage
examples) would be great.
> R.version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 6...
2020 May 01
4
paste(character(0), collapse="", recycle0=FALSE) should be ""
Without 'collapse', 'paste' pastes (concatenates) its arguments elementwise (separated by 'sep', " " by default). New in R devel and R patched, specifying recycle0 = FALSE makes mixing zero-length and nonzero-length arguments results in length zero. The result of paste(n, "th", sep = "", recycle0 = FALSE) always have the same length as...
2005 Aug 08
1
modifying argument of a .C call (DUP=FALSE)
I have a huge matrix on which I need to do a simple (elementwise)
transformation. Two of these matrices cannot fit in the memory, so I cannot
do this in R.
I thought of writing some C code to do this and calling it using .C with
DUP=FALSE. All I need is a simple for loop that replaces elements with
their new value, something like
void transform(double *a, in...
2001 Sep 23
1
outer
...nt it to do.
i hav a function only defined for scalars
fun(n,k)
and i want to do
outer(1:5,1:5,function(x,y) fun(x,y))
(i know this is written somewhat clumsy)
to get an array with the values of fun
to use it as an input for image
this does not work since
outer assumes then fun works on arrays elementwise.
what is the easiest way of getting what i want?
outer in some lisp like variants and in mathematica will work with the
function argument being a
scalar argument only function.
r is different here.
--
Erich Neuwirth, Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsi...
2003 Oct 06
1
visualizing transition probability matrices
...ouple of (~200) 3x3 transition probability matrices (ie each
defines a Markov chain). They are all estimated from the same
underlying process, so it ie meaningful to take their elemetwise mean
and standard deviation. [1]
First question: supposing that they are given in a list l, how do I
get their elementwise mean and standard deviation? Fortunately, the
mean of trans. prob. matrices also remains a transition probability
matrix. I'm not sure if taking the standard deviation is meaningful,
though. Any suggestions?
Second (more important): what would be the best way of visualizing the
3x3 mean and st...
2007 Nov 05
1
Should numeric()/character() etc initialize with NA instead of 0 or ""?
Wouldn't it make programming more error-resistant if vectors were
initialized with missing data, instad of zeroes or ""?
That way, if you assign values to a vector elementwise and you miss some
elements
(because their indices were not selected or because the assignment didn't
work out, see below for code examples)
this would be immediately obvious from the value of the vector elements
themselves
and programming errors would be far less easy to overlook.
e.g.
x <...
2008 Jun 18
2
ifelse and "&&" vs "&"
Hi,
I noticed whether some one could explain why "&" and "&&" behave differently in data frame transformations.
Consider the following :
a<-data.frame(r=c(0,0,2,3),g=c(0,2,0,2.1))
Then:
> transform(a,R=ifelse(r>0 && g> 0,log(r/g),NA))
r g R
1 0 0.0 NA
2 0 2.0 NA
3 2 0.0 NA
4 3 2.1 NA
but
> transform(a,R=ifelse(r>0 & g>
2020 May 15
2
paste(character(0), collapse="", recycle0=FALSE) should be ""
...ot;
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Apr 30, 2020 at 9:56 PM suharto_anggono--- via R-devel <
> r-devel at r-project.org> wrote:
>
>> Without 'collapse', 'paste' pastes (concatenates) its arguments
>> elementwise (separated by 'sep', " " by default). New in R devel and R
>> patched, specifying recycle0 = FALSE makes mixing zero-length and
>> nonzero-length arguments results in length zero. The result of paste(n,
>> "th", sep = "", recycle0 = FALSE) alw...
2011 Nov 04
6
Matrix element-by-element multiplication
is there a way to do element-by-element multiplication as in Gauss
and MATLAB, as shown below? Thanks.
---
a
1.0000000
2.0000000
3.0000000
x
1.0000000 2.0000000 3.0000000
2.0000000 4.0000000 6.0000000
3.0000000 6.0000000 9.0000000
a.*x
1.0000000 2.0000000 3.0000000
4.0000000
2005 Sep 05
3
help
Dear helpeRs,
I seem to be a little bit confused on the result I am getting from the
few codes below:
> u=v=seq(0,1,length=30)
> u
[1] 0.00000000 0.03448276 0.06896552 0.10344828 0.13793103 0.17241379
[7] 0.20689655 0.24137931 0.27586207 0.31034483 0.34482759 0.37931034
[13] 0.41379310 0.44827586 0.48275862 0.51724138 0.55172414 0.58620690
[19] 0.62068966 0.65517241 0.68965517 0.72413793
2024 Feb 27
2
converting MATLAB -> R | element-wise operation
Why anything but sweep?
The fundamental data type in Matlab is a matrix... they don't have vectors, they have Nx1 matrices and 1xM matrices.
Vectors don't have any concept of "row" vs. "column". Straight division is always elementwise with recycling as needed, and matrices are really vectors in row-major order:
1 2 3
4 5 6
is really
1 4 2 5 3 6
and when you do straight division NN / lambda then lambda is repeated:
1 4 2 5 3 6
2 3 4 2 3 4
to get
0.5 1.3 0.5 2.5 1.0 1.5
but if you transpose first
1 4
2 5
3 6
then that co...