apply() Function in R (R Tutorial 1.14)

Learn how to use the “apply()” function in R, to apply a function to all rows or columns of a data frame. The apply function essentially is a specialized loop function, although it is more efficient than a simple for-loop. You will also learn the use of the “ColMeans”, “ColSums”, “RowMeans”, and “RowSums” functions.
This video is a tutorial for programming in R Statistical Software for Statistics and Data Science beginners, using RStudio.

You can access the dataset (Stock Example Data) and R script (Apply Function) here:
(https://bit.ly/2rOfgEJ)

• Views:13,779 views
• Rating:
• Categories:
• Tags:

mao rui says:

Intuitive!

케이오튜브 KOTUBE says:

I love MarinStatsLectures. It has been a great help for me to prepare for my grad school thesis. Thank you for your effort and I am a big fan of you Marin!

When I am using apply command then I am getting following error.

apply(X=StockData, MARGIN = 2, FUN = mean)
X Stock1 Stock2 Stock3 Stock4
NA NA NA NA NA
Warning messages:
1: In mean.default(newX[, i], …) :
argument is not numeric or logical: returning NA
2: In mean.default(newX[, i], …) :
argument is not numeric or logical: returning NA
3: In mean.default(newX[, i], …) :
argument is not numeric or logical: returning NA
4: In mean.default(newX[, i], …) :
argument is not numeric or logical: returning NA
5: In mean.default(newX[, i], …) :
argument is not numeric or logical: returning NA

LEIYUE RAN says:

Hi guys, anyone happen to have the same problem of points not showing on the graph?

Green Cat says:

Tapply and lapply would also be cool to see here 🙂

Sho Islam says:

This is a great video, especially as I’m still very new in R!!

Hossam Mohamed says:

When i try to generate plots using apply function it only gives one plot , not a separate plot for each column ??

suman das says:

i don’t want to sum of all variables…i want to sum some variables..how do i write it??? rowsum

Limin Jin says:

Thanks so much! This is the best R tutorial i’ve ever seen!!! But the problem is that the dataset is not avaliable now, since the web link is invalide now. could you please post a new link consisting the dataset?

Stefan says:

Thanks for your amazing video series! I profit a lot from them.
In RStudio under the files, plots, packages pane. Shows the section packages the already installed packages? And when you activate them then you loaded the library of the package?

Paul Elliot says:

Thanks very much for this video. I have a doubt. What should I do if I want to boxplot stock1, stock2, stock 3 and stock 4, for Day1, Day2… Day10. So 6 boxplots for each of the days, with stock1-4 in each of those boxplots. Hope I’m making sense. Many thanks!

Jesus Rojas says:

Dude, I’ll send you a copy of my master’s once is done, you deserve at least 20% of it, thanks so much for your videos!!! @MarinStatsLectures-R Programming & Statistics

MeiKimchi says:

I tried to use RowSums and apply, but im getting different result ?