Wolfpack
Wolfpack

Reputation: 59

Using a for loop to find IQR in iris

I'm trying to use a for loop to find the IQR of the first 4 columns in the iris dataset.

I have tried this:

for(IQR in iris[,1:4]){
print(IQR(iris[,1:4]))
}

But I only receive an error. I know there are easier ways to do this for example apply() and sapply(), but I would like to know how to use the for loop because I have no experience with it and I want to see how it would work. Any help is greatly appreciated. Thank you.

Upvotes: 0

Views: 174

Answers (1)

mr.joshuagordon
mr.joshuagordon

Reputation: 764

i iterates from 1 to 4

call the ith column with data[,i]

for(i in 1:4){
  print(IQR(iris[,i]))
}

Upvotes: 1

Related Questions