Use as.logical
:
x <- NA_real_
is.logical(x)
## [1] FALSE
is.numeric(x)
## [1] TRUE
xL <- as.logical(x)
is.logical(xL)
## [1] TRUE
is.numeric(xL)
## [1] FALSE
문제
I'm reading a data frame with some columns having "NA" values.While calculating I found that
>p1 <- met.df[20,"D3_p-value"]#some arbitray 20th ROW of Dataframe
> p1
[1] NA
> is.numeric(p1)
[1] TRUE
> x <- NA
> x
[1] NA
> is.numeric(x)
[1] FALSE
> str(p1)
num NA
> str(x)
logi NA
How to convert 'p1' to a logical "NA" ?
Thanks
해결책
Use as.logical
:
x <- NA_real_
is.logical(x)
## [1] FALSE
is.numeric(x)
## [1] TRUE
xL <- as.logical(x)
is.logical(xL)
## [1] TRUE
is.numeric(xL)
## [1] FALSE