How to access any element of data frame in R

r

#1

I want to access the 47 element of Species column in iris data set but I am getting error and I am not able to understand why
iris$Species[,47]
Error in [.default(iris$Species, , 47) : incorrect number of dimensions


#2

The correct way to do this would be iris$Species[47] This is because once you use iris$Species you have already subsetted the one-dimensional vector. (If you don’t put a specific number/vector after the comma all the values in that dimension are returned.) Thus, it makes no sense to give the vector two inputs and a single digit input is sufficient.