How to solve it. error:Error in data[[rowvar]] : attempt to select less than one element

The problem is caused by row.names = “a”. Data set must have different row names. If you try to name all rows “a”, you get the error. If you have a vector which contains the row names you want to use, you can do this.

> a <- c("A", "B", "C")
> read.table("demo.txt", header = TRUE, row.names = a)
  clo1 clo2 clo3
A    1    2    3
B    1    2    3
C    5    6    7

Leave a Comment