在R中过滤Tibbles

时间:2018-01-10 04:32:30

标签: r dataframe filter

我是一个尝试学习R绳索的新手。我有一个包含32列和8000多行的数据集。

library(readr)
library(dplyr)
library(tidyr)

Ind <- read_csv("Industrial.csv")

Ind %>%
  select(City,Period,Year,'Average Equivalent Yield Prime Grade') %>%
  filter('City' == "Sydney")

当我禁用过滤器时,我似乎将所选列设置为ok,当我尝试按城市过滤时,不会返回任何结果。

# A tibble: 8,080 x 4
   City   Period  Year `Average Equivalent Yield Prime Grade`
   <chr>  <chr>  <int>                                  <dbl>
 1 Sydney Q2      1975                                     NA
 2 Sydney Q2      1975                                     NA
 3 Sydney Q2      1975                                     NA
 4 Sydney Q2      1975                                     NA
 5 Sydney Q2      1975                                     NA
 6 Sydney Q2      1975                                     NA
 7 Sydney Q2      1975                                     NA
 8 Sydney Q2      1975                                     NA
 9 Sydney Q2      1975                                     NA
10 Sydney Q2      1975                                     NA

数据结构如下所示:

Classes ‘tbl_df’, ‘tbl’ and 'data.frame':       8080 obs. of  32 variables:
 $ Column                                          : chr  "RowData" "RowData" "RowData" "RowData" ...
 $ Global                                          : chr  "Global" "Global" "Global" "Global" ...
 $ Region                                          : chr  "Asia Pacific" "Asia Pacific" "Asia Pacific" "Asia Pacific" ...
 $ Country                                         : chr  "Australia" "Australia" "Australia" "Australia" ...
 $ State                                           : chr  "New South Wales" "New South Wales" "New South Wales" "New South Wales" ...
 $ City                                            : chr  "Sydney" "Sydney" "Sydney" "Sydney" ...
 $ Sub Market                                      : chr  "Sydney Metro" "Sydney Metro" "Sydney Metro" "Sydney Metro" ...
 $ GeoLevel7                                       : chr  NA "Inner West" "Inner West" "North" ...
 $ GeoLevel8                                       : chr  NA NA NA NA ...
 $ Property Type                                   : chr  "Distribution Warehouse/Logistics" "Distribution Warehouse/Logistics" "High Tech" "Distribution Warehouse/Logistics" ...
 $ Currency                                        : chr  "AUD" "AUD" "AUD" "AUD" ...
 $ Measurement                                     : chr  "m<U+00B2>" "m<U+00B2>" "m<U+00B2>" "m<U+00B2>" ...
 $ PaymentFrequency                                : chr  "Per Annum" "Per Annum" "Per Annum" "Per Annum" ...
 $ Period                                          : chr  "Q2" "Q2" "Q2" "Q2" ...
 $ Year                                            : int  1975 1975 1975 1975 1975 1975 1975 1975 1975 1975 ...
 $ Land Value 2,000sqm Serviced Lots               : int  NA NA NA NA NA NA NA NA NA NA ...
 $ Existing Net Rental Growth Prime Grade q-o-q    : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Existing Net Rental Growth Prime Grade y-o-y    : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Existing Net Rent Secondary Grade               : int  NA NA NA NA NA NA NA NA NA 22 ...
 $ Existing Net Rental Growth Secondary Grade q-o-q: num  NA NA NA NA NA NA NA NA NA NA ...
 $ Existing Net Rental Growth Secondary Grade y-o-y: num  NA NA NA NA NA NA NA NA NA NA ...
 $ Pre-lease Net Rent                              : chr  NA NA NA NA ...
 $ Pre-lease Net Rental Growth q-o-q               : chr  NA NA NA NA ...
 $ Pre-lease Net Rental Growth y-o-y               : chr  NA NA NA NA ...
 $ Equivalent Yield Lower Prime Grade              : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Average Equivalent Yield Prime Grade            : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Equivalent Yield Upper Secondary Grade          : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Equivalent Yield Lower Secondary Grade          : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Average Equivalent Yield Secondary Grade        : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Capital Value Indicator Prime Grade             : int  NA NA NA NA NA NA NA NA NA NA ...
 $ Capital Value Growth (GFA) q-o-q                : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Capital Value Growth (GFA) y-o-y                : num  NA NA NA NA NA NA NA NA NA NA ...
 - attr(*, "problems")=Classes ‘tbl_df’, ‘tbl’ and 'data.frame':        1203 obs. of  5 variables:
  ..$ row     : int  1204 1206 1208 1243 1245 1247 1282 1286 1321 1323 ...
  ..$ col     : chr  "Existing Net Rent Secondary Grade" "Existing Net Rent Secondary Grade" "Existing Net Rent Secondary Grade" "Existing Net Rent Secondary Grade" ...
  ..$ expected: chr  "no trailing characters" "no trailing characters" "no trailing characters" "no trailing characters" ...
  ..$ actual  : chr  ".2" ".6" ".95" ".76" ...
  ..$ file    : chr  "'Industrial.csv'" "'Industrial.csv'" "'Industrial.csv'" "'Industrial.csv'" ...
 - attr(*, "spec")=List of 2
  ..$ cols   :List of 32
  .. ..$ Column                                          : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Global                                          : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Region                                          : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Country                                         : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ State                                           : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ City                                            : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Sub Market                                      : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ GeoLevel7                                       : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ GeoLevel8                                       : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Property Type                                   : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Currency                                        : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Measurement                                     : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ PaymentFrequency                                : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Period                                          : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Year                                            : list()
  .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
  .. ..$ Land Value 2,000sqm Serviced Lots               : list()
  .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
  .. ..$ Existing Net Rental Growth Prime Grade q-o-q    : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Existing Net Rental Growth Prime Grade y-o-y    : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Existing Net Rent Secondary Grade               : list()
  .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
  .. ..$ Existing Net Rental Growth Secondary Grade q-o-q: list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Existing Net Rental Growth Secondary Grade y-o-y: list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Pre-lease Net Rent                              : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Pre-lease Net Rental Growth q-o-q               : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Pre-lease Net Rental Growth y-o-y               : list()
  .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
  .. ..$ Equivalent Yield Lower Prime Grade              : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Average Equivalent Yield Prime Grade            : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Equivalent Yield Upper Secondary Grade          : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Equivalent Yield Lower Secondary Grade          : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Average Equivalent Yield Secondary Grade        : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Capital Value Indicator Prime Grade             : list()
  .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
  .. ..$ Capital Value Growth (GFA) q-o-q                : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  .. ..$ Capital Value Growth (GFA) y-o-y                : list()
  .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
  ..$ default: list()
  .. ..- attr(*, "class")= chr  "collector_guess" "collector"
  ..- attr(*, "class")= chr "col_spec"

我需要做什么数据按摩才能获得所需的结果?

提前致谢。

0 个答案:

没有答案