Conditional Statements
Title
Question
Use the built-in data set iris. Find the Species, in which Sepal.Length is greater than Petal.Length.
please send the answer
R Conditional-Statements 11-12 min 0-10 sec
Answers:
Count = 0
Species = vector(mode = "character",length = nrow(iris))
for(i in 1:nrow(iris))
{
if(iris$Sepal.Length[i]>iris$Petal.Length[i])
{
Species[Count + 1] <- as.character(iris$Species[i])
Count = Count + 1
}
Species = vector(mode = "character",length = nrow(iris))
for(i in 1:nrow(iris))
{
if(iris$Sepal.Length[i]>iris$Petal.Length[i])
{
Species[Count + 1] <- as.character(iris$Species[i])
Count = Count + 1
}
}
Species
Login to add comment