[R] Removing White spaces with NA
arun
smartpink111 at yahoo.com
Sat Apr 5 05:21:57 CEST 2014
Hi,
Check if this works:
n <- 1e7
dat <- data.frame(Col1=c("A", "", "B","C", "","","D",rep('',n)), stringsAsFactors=FALSE)
dat2 <- dat
dat[dat==''] <- NA
which(dat$Col1=='')
#integer(0)
#or
dat2$Col1[dat2$Col1==''] <- NA
which(dat2$Col1=='')
#integer(0)
A.K.
On Wednesday, April 2, 2014 2:20 PM, arun <smartpink111 at yahoo.com> wrote:
Hi,
May be this helps:
dat <- data.frame(Col1=c("A", "", "B","C", "","","D"), stringsAsFactors=FALSE)
is.na(dat) <- dat==''
dat$Col1
#[1] "A" NA "B" "C" NA NA "D"
A.K.
Hi All, I have a table and a column with values as below Col1
A B
C D I need to replace the Empty cells with the value NA as below
Col1
A
NA
B
C
NA
NA
D I tried a code, which was not working.
Table.name$column.name <- gsub("","NA", table.name$column.name) Can anyone help me with this ?
Thanks and regards,
Praveen
More information about the R-help
mailing list