Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Shiny

You're reading from   Learning Shiny Make the most of R's dynamic capabilities and implement web applications with Shiny

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785280900
Length 246 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Hernan Resnizky Hernan Resnizky
Author Profile Icon Hernan Resnizky
Hernan Resnizky
Hernan Resnizky Hernan Resnizky
Author Profile Icon Hernan Resnizky
Hernan Resnizky
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introducing R, RStudio, and Shiny FREE CHAPTER 2. First Steps towards Programming in R 3. An Introduction to Data Processing in R 4. Shiny Structure – Reactivity Concepts 5. Shiny in Depth – A Deep Dive into Shiny's World 6. Using R's Visualization Alternatives in Shiny 7. Advanced Functions in Shiny 8. Shiny and HTML/JavaScript 9. Interactive Graphics in Shiny 10. Sharing Applications 11. From White Paper to a Full Application Index

The lapply, vapply, sapply, and apply functions


These functions are equivalent to a for-each loop with the advantage that they are much more efficient in terms of performance. Basically, the function is applied over every item in a vectorized object. Its main structure is:

function(object_to_iterate_on, function, additional_arguments(separated by commas))

vapply() and apply() have additional arguments that will be covered in detail in the expanded explanations of these functions.

The function argument can be an already defined function (with its arguments), as follows:

sample.list <- list(a=runif(100,0,1), b=runif(500,0,100),
c=runif(35,0,200))
sapply(sample.list, quantile, probs=0.75)
##       a.75%       b.75%       c.75% 
##   0.7145661  77.4817679 158.9351519

Also, the function can be defined within the same apply-function call (these types of functions are called anonymous functions), as follows:

sapply(sample.list, function(x) round(sum(x+2)))
##     a     b     c 
##   250 27235...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime