Select 行使用 sqldf 逻辑为 TRUE
Select rows with logical TRUE using sqldf
我正在使用这个:
NewDf <- sqldf("select * from OldDf where Test = 'TRUE'")
但我在 NewDf 中得到零行。 OldDf 中肯定有 TRUE 的行(Test 列是合乎逻辑的值:TRUE 和 FALSE).
有什么想法吗?
P.S.: 这有效:
NewDf <- subset(OldDf, Test != 'FALSE')
sqldf 将逻辑值存储为 0
和 1
整数,请参见以下示例:
# dummy data
OldDf <- head(mtcars[, 1:2])
OldDf$Test <- c(TRUE, FALSE)
OldDf
# mpg cyl Test
# Mazda RX4 21.0 6 TRUE
# Mazda RX4 Wag 21.0 6 FALSE
# Datsun 710 22.8 4 TRUE
# Hornet 4 Drive 21.4 6 FALSE
# Hornet Sportabout 18.7 8 TRUE
# Valiant 18.1 6 FALSE
library(sqldf)
sqldf("select * from OldDf where Test = 1")
# mpg cyl Test
# 1 21.0 6 TRUE
# 2 22.8 4 TRUE
# 3 18.7 8 TRUE
# This also works, to filter on TRUE
sqldf("select * from OldDf where Test")
# mpg cyl Test
# 1 21.0 6 TRUE
# 2 22.8 4 TRUE
# 3 18.7 8 TRUE
# To get FALSE
sqldf("select * from OldDf where NOT Test")
# mpg cyl Test
# 1 21.0 6 FALSE
# 2 21.4 6 FALSE
# 3 18.1 6 FALSE
我正在使用这个:
NewDf <- sqldf("select * from OldDf where Test = 'TRUE'")
但我在 NewDf 中得到零行。 OldDf 中肯定有 TRUE 的行(Test 列是合乎逻辑的值:TRUE 和 FALSE).
有什么想法吗?
P.S.: 这有效:
NewDf <- subset(OldDf, Test != 'FALSE')
sqldf 将逻辑值存储为 0
和 1
整数,请参见以下示例:
# dummy data
OldDf <- head(mtcars[, 1:2])
OldDf$Test <- c(TRUE, FALSE)
OldDf
# mpg cyl Test
# Mazda RX4 21.0 6 TRUE
# Mazda RX4 Wag 21.0 6 FALSE
# Datsun 710 22.8 4 TRUE
# Hornet 4 Drive 21.4 6 FALSE
# Hornet Sportabout 18.7 8 TRUE
# Valiant 18.1 6 FALSE
library(sqldf)
sqldf("select * from OldDf where Test = 1")
# mpg cyl Test
# 1 21.0 6 TRUE
# 2 22.8 4 TRUE
# 3 18.7 8 TRUE
# This also works, to filter on TRUE
sqldf("select * from OldDf where Test")
# mpg cyl Test
# 1 21.0 6 TRUE
# 2 22.8 4 TRUE
# 3 18.7 8 TRUE
# To get FALSE
sqldf("select * from OldDf where NOT Test")
# mpg cyl Test
# 1 21.0 6 FALSE
# 2 21.4 6 FALSE
# 3 18.1 6 FALSE