Is R’s apply family more than syntactic sugar?

The apply functions in R don’t provide improved performance over other looping functions (e.g. for). One exception to this is lapply which can be a little faster because it does more work in C code than in R (see this question for an example of this). But in general, the rule is that you should … Read more

When should I (not) want to use pandas apply() in my code?

apply, the Convenience Function you Never Needed We start by addressing the questions in the OP, one by one. “If apply is so bad, then why is it in the API?” DataFrame.apply and Series.apply are convenience functions defined on DataFrame and Series object respectively. apply accepts any user defined function that applies a transformation/aggregation on … Read more

how to apply a function on a data set?

I’m at least not quite sure whether I understood correct. Maybe a better question could improve the answers… DF <- data.frame(Tree = c(4382, 4383, 4384, 5385, 4386), a = c(21.88, 13.93, 19.69, 20.02, 11.07), b = c(9.59, 12.95, 9.78, 8.23, 23.20), k = c(0.0538, 0.0811, 0.0597, 0.0489, 0.1276)) DOY <- c(1:365) DF_new <- data.frame(sapply(1:length(DF$Tree), function(x)(DF$a[x]*exp(-exp(DF$b[x]-DF$k[x]*DOY))))) … Read more