我有一个数据集train_cab
,其中包含以下信息:
fare_amount pickup_datetime pickup_longitude pickup_latitude dropoff_longitute dropoff_latitude
4.5 1245066981 -73.8 40.7 -73.8 40.7
16.9 1262690536 -74.0 40.7 -74.0 40.8
5.7 1313607900 -74.0 40.8 -74.0 40.8
7.7 1334962842 -74.0 40.7 -74.0 40.8
5.3 1268101260 -74.0 40.8 -74.0 40.8
12.1 1294287645 -74.0 40.7 -74.0 40.8
7.5 1353423900 -74.0 40.8 -74.0 40.8
16.5 1325677920 -74.0 40.8 -74.0 40.8
15.0 1354520400 -74.0 40.7 -74.0 40.7
8.9 1251834060 -74.0 40.7 -74.0 40.8
我想对其进行切片,并仅使用范围内的特定值; 我使用以下代码对其进行了子集化:
subset(train_cab, (fare_amount >= 2.50 & fare_amount<=600))
subset(train_cab,(pickup_latitude >= -73.00 & pickup_latitude <= 74.83))
subset(train_cab,(dropoff_latitude >= -73.00 & dropoff_latitude <= 74.83))
subset(train_cab,(pickup_longitude >= -74.025 & pickup_longitude <= 74.930))
subset(train_cab,(dropoff_longitude >= -73.00 & dropoff_longitude <= 74.83))
subset(train_cab,(passenger_count >= 1 & passenger_count <= 7))
代码执行良好,没有任何错误,但是检索了空白数据框。
我要去哪里了。我会很感激的。
我通过将主数据帧分配为以下方式进行了尝试:
train_cab <- subset(train_cab, (fare_amount >= 2.50 & fare_amount<=600))
train_cab <- subset(train_cab,(pickup_latitude >= -73.00 & pickup_latitude <= 74.83))
train_cab <- subset(train_cab,(dropoff_latitude >= -73.00 & dropoff_latitude <= 74.83))
train_cab <- subset(train_cab,(pickup_longitude >= -74.025 & pickup_longitude <= 74.930))
train_cab <- subset(train_cab,(dropoff_longitude >= -73.00 & dropoff_longitude <= 74.83))
train_cab <- subset(train_cab,(passenger_count >= 1 & passenger_count <= 7))
但是此代码将删除纬度和经度列中的所有正值。