in Education by
I use the function apply whenever I want to do something “map”py in R I want to know about the difference between them - how sapply, lapply, etc apply the function to be in input/grouped input, I just go through them until I get what I want as I don’t know what output will look like or what input will be. So please can someone tell me when should I use which one and how? Bonus question: Can plyr or reshape can be used to replace these entirely? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can check the help file in R for the apply function, most of the functionality of apply family is covered by plyr package, but still some base functions are worth learning. I am giving examples of a few below: Apply: used to apply a function to the rows or columns of a matrix, not advised for data frames it coerce to a matrix first. M <- matrix(seq(2,17), 5, 5) apply(M,2,min) [2] 3 4 5 6 apply(M,3, max) [2] 5 9 13 17 2.tapply: If function is applied to subsets of a vector, and subset is defined by some other vector which in most of the cases is a factor. A vector: x <- 1:21 factor (of the same length!) defining groups: y <- factor(rep(letters[2:6], each = 4)) Add up the values in a within each subgroup defined by b: tapply(a,b,sum)q w e r t 11 27 43 59 75 For all others just check the help of R or comment down below.

Related questions

0 votes
    I use the function apply whenever I want to do something map py in R I want to know about the ... questions and answers pdf, Verbal Reasoning interview questions for beginners...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    Cognizant Bulk Hiring Freshers and Experienced 2023| CTC 5 to 15 LPA | Apply Now...
asked Feb 27, 2023 in Technology by Editorial Staff
0 votes
    My initial dataframe looks: library(tidyverse) df...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    My initial dataframe looks: library(tidyverse) df...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Which of the following finds row sums for each level of a grouping variable? (a) as.numeric(x) (b) ... Regression of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following finds row sums for each level of a grouping variable? (a) rowSums (x, na.rm = ... Regression of R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    ___________ function is used to apply an expression for a given dataset. (a) This() (b) With() (c) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    What are Aggregate and Scalar functions?...
asked Dec 11, 2020 in Technology by JackTerrance
0 votes
    How can you print a \ (backslash) using any of the printf() family of functions?...
asked Jan 17, 2021 in Technology by JackTerrance
0 votes
    Which of the following package contains functions for reading and displaying satellite data for oceanographic ... Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    ________ functions can be built which contain all of the necessary data for evaluating the function. (a) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    .RData extension used when we save data using the functions ___________ (a) save() (b) save.image() (c ... Operations of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    R has many functions regarding ________________ (a) Statistics, Biotechnology (b) Probability, Microbiology (c) ... R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which Package contains most fundamental functions to run R? (a) root (b) child (c) base (d) parent The ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How many functions exist for wrangling the data with dplyr package? (a) one (b) seven (c) three (d) ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
...