Reputation: 1153
I have a dataset a
and I would like to get all lines from 1 - 10000 that contain no "NA" or "null".
They way I've read my dataset is this:
a<- read.table("GDS4879.CLEAN", header = TRUE, na.strings = NA)
Is it possible to do this using R?
Upvotes: 0
Views: 662
Reputation: 1153
First you want to clear all NAs from the dataset. You can achieve that by using complete.cases
a[complete.cases(a),]
Then use the head function to get the first 10000
a <- head(a,10000)
Upvotes: 0
Reputation: 57210
Pass "NA"
and "null"
to na.strings
parameter, then after reading the file call na.omit()
.
Example :
(here I read the table from a string, but you can easily change the code to read your file)
text <-
"A,B,C,D
NA,1,2,3
4,5,6,7
8,9,10,11
12,13,null,14"
a <- read.table(text=text, header=TRUE, sep=',',row.names=NULL,
na.strings = c('NA','null')) # this parameter turns "NA" and "null" strings to NA values
a <- na.omit(a) # this removes the strings containing NAs
> a
A B C D
2 4 5 6 7
3 8 9 10 11
Upvotes: 3