문제

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top