Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rowSapply for matrices? #32

Open
berndbischl opened this issue Apr 23, 2014 · 2 comments
Open

rowSapply for matrices? #32

berndbischl opened this issue Apr 23, 2014 · 2 comments

Comments

@berndbischl
Copy link
Owner

How do I do this operation est in R?

  • given A matrix A
  • I would like to apply a function to every row.
  • this function returns a vector (a new row)

I want the resulting matrix.

@jakobbossek
Copy link
Collaborator

I think this is what you want.

A = matrix(1:10, 5, 2)
print(A)
fn = function(x) x^2

B = t(apply(A, 1, fn)) # this is what you want
print(B)

@berndbischl
Copy link
Owner Author

Yes, sure.

I just do not find this very readable, especially because of t()

Maybe we should have a REALLY nice family of all apply-variants we want in HELL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants