r - Read in only certain rows -
i have set of data below. has few rows of unwanted characters before numbers want read in, few unwanted rows after data. created substring serve first column, purely numerical. there data, when set read in, above , below these numericals converted na. there way, other skip , nrow, can remove na rows , read in rows numerical?
x<-read.csv("..."), header=false, na.strings="y") y<-substr(x$v1,1,8) y<-as.numeric(y) x2<-cbind(y,x1) x2<-as.data.frame(x2)
i have tried:
if (x$y == is.numeric) { print(x) } else { print("")}
but wrong errors. have been trying different combinations of above code, as:
x3<-sapply(x$y,is.numeric) x[x3,]
but nothing try working.. either off or missing something.
update: able both methods answered below.. problem is, since rows above numeric rows contained characters, columns factors rather numeric. rather deleting rows, temporarily removing them. there way permanently remove them columns class numeric?
if case of remove rows containing nas, have tried using complete.cases
? perhaps like:
x2[complete.cases(x2),]
also if great if provide minimal reproducible sample.
Comments
Post a Comment