Skip to content
Prev 166539 / 398502 Next

Matrix: Problem with the code

Charlotte: I ran your code because I wasn't clear on it and your way 
would cause more matrices than the person requested. So
I think the code below it, although not too short, does what the person 
asked. Thanks though because I understand outer better now.

temp <- matrix(c(1,2,3,4,5,6),ncol=2)
print(temp)

#One of those more elegant ways:
print(temp)
outer(temp,1:p,'^')One of those more elegant ways:


# THIS WAY I THINK GIVES WHAT THEY WANT

sapply(1:ncol(temp), function(.col) {
   temp[,.col]^.col
})
On Fri, Jan 9, 2009 at 7:40 PM, Charlotte Wickham wrote: