Finding non-numeric data in an R data frame or vector

前端 未结 2 1220
萌比男神i
萌比男神i 2020-12-05 19:00

I have read in some lengthy data with read.csv(), and to my surprise the data is coming out as factors rather than numbers, so I\'m guessing there must be at least one non-n

2条回答
  •  不思量自难忘°
    2020-12-05 19:30

    An alternative could be to check which entries in the vector contain any characters other than a number:

    df <- data.frame(c(1,2,3,4,"five",6,7,8,"nine",10))
    which(!grepl('^[0-9]',df[[1]]))
    ## 5 9 
    

提交回复
热议问题