Apply-style commands in R
[This article was first published on The Data Monkey, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Here’s a quick table of what I think are the most useful apply-style commands in R: Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Function | Input | Output | Best for |
apply | Rectangular | Rectangular or vector | Applying function to rows or columns |
lapply | Anything | List | Non-trivial operations on almost any data type |
sapply | Anything | Simplified (if possible) or list | Same as lapply, but with simplified output |
plyr::ddply | data.frame | data.frame | Applying function to groupings defined by variables |
To leave a comment for the author, please follow the link and comment on their blog: The Data Monkey.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.