1.

Explain The Usage Of Which() Function In R Language?

Answer»

which() function determines the position of elements in a LOGICAL vector that are TRUE. In the below EXAMPLE, we are finding the row number WHEREIN the maximum VALUE of variable v1 is recorded.

mydata=data.frame(v1 = c(2,4,12,3,6))

which(mydata$v1==max(mydata$v1))

It returns 3 as 12 is the maximum value and it is at 3RD row in the variable x=v1.

which() function determines the position of elements in a logical vector that are TRUE. In the below example, we are finding the row number wherein the maximum value of variable v1 is recorded.

mydata=data.frame(v1 = c(2,4,12,3,6))

which(mydata$v1==max(mydata$v1))

It returns 3 as 12 is the maximum value and it is at 3rd row in the variable x=v1.



Discussion

No Comment Found