getting the labels of the specified index instead of converting to matrix and then to factor