    
  


    ,           R,     r4ds.had.co.nz,       ,               -.      R,    -.




  ..,        , .







,             ,       ,             .             ,        ,     .     -           ,                 .    ,                        ,   ,    ,         ?           ,    -          .   ,  .          ,    .      : Electronic Visualization Laboratory, Kitware, -  ,    NASA,    ,   ,    ,      ,     .     : IEEE Visualization, SIGGRAPH, EuroVis,         , Eurographics, PacificVis.  ,         .         ,   80%-90%    .     ,       ,   1973    . .                  .  ,        ,     :








   ,          ,               :








                    R. ,        -    iSpring Suite (https://www.ispring.ru/ispring-suite)    GeoGebra (https://www.geogebra.org).     ,           ,      .  ?

        R      (https://www.r-project.org).     : https://cran.cmm.msu.ru/bin/windows/base/R-4.0.2-win.exe          :








  ,         GNU,    R.  ,     ,      ,     GNU  1988 .,         . Ÿ    GNU GPL    GPL,    ,       .  , R       ,     1991 .   ,   1990       ,        ;   2 GPL     1991 ,      GNU Library General Public License (GNU LGPL, LGPL),    2,   ,      .








    :








      .        x64  x32  ,   x64       32      64-,  32- ,    x32     4  ,   32-      3  ( ,     4  ( ) ,  32-        3-,      ,   ,  ,    ).  ,           .








       .          ,     .








     RStudio (https://rstudio.com)     ,       .   ,  ,  RStudio                 R.  RStudio Desktop   Linux, OS X  Windows.  ,  RStudio Server      RStudio    Linux-.

  RStudio      R.








         ,       .








       ,      ,         RStudio   .   RStudio     C++    Qt    ,              .    ,  ,  Qt5WebEngineCore.dll.         .








  R  RStudio,     /R/R x64,        .      RStudio,      :








       (http://factominer.free.fr),     R   

install.packages("FactoMineR")

install.packages("Factoshiny")

      .








       / /FactoMineR/ʻ,      / /Factoshiny/ʻ.      .

 ,      Factoshiny.  ,       ,    ,     ,      (:    PCA,   CA,    MCA,   MFA,   ). Factoshiny       .           .     ,  .

        ,  ,    .       .      ,     ,   .  ,  ,     ,   Factoshiny,    .         ,        , ,            .

  ,      Google-  Excel- table.xlsx   - (   5-7   7-10 )         R.          R (   #  ,       ,          ):

1)      .xls

library(readxl)

2)    

library(Factoshiny)

3)    My_table   table.xlsx

My_table < read_excel("C:/  /table.xlsx")

4)          PCA,   1, 2, 3, 4, 5, 6, 7, 8        My_table

PCAshiny(My_table[,c(1, 2, 3, 4, 5, 6, 7, 8)])

5)      , ,  /     ,  .

,   ,    D:\test.xlsx        7  7 :








 RStudio         R   :

library(readxl)

library(Factoshiny)

My_table < read_excel("D:/test.xlsx")

PCAshiny(My_table[,c(1, 3, 4, 5, 6, 7)])

   :








      .   1        ;   2     ;   3          :








     :

      1  4  ,         (   ,      52.06%,     28.27% );

     ,    2, 3  5,      2, 3  5;

 20     ,      ,    1, 4, 6, 8   ;

2  7   ,   7,            2;

        ,        1  4,    3  5  ,  1  4,   3  5   .

      ,                .




 1.  



     ,            R: ,     R,     ,  ,     .  ,       ,  ,   ,   ,  ,   ,     .     -  ,           R,       ,   .  ,  ,         .       ,         ,     .  ,             R,      .               R.




1.    


        ,     ,        .     R.   ,   ,   ,    ,       R.        R,      R        .

 ,      R,       .         ,     .  ,   ,    ,      .       ,           ,             .

 ,      ,      ,   :

1)    (,      ,       );

2)   ,       (,       );

3)      (,     ).

 ,               :   .       ,           .

     .      ,    ,       .     ,    ,      .    ,    ,          .

    .  ,      ,     ,    .   R        ,    .      ,     .        ,             .  ,          .

   :   ,      .    ,      ,          .

     ,        ,      ,   ,    ,       ,           .

        ,      .    80/20 ( ):    80%     ,   ,     ,     20%.

           ,        (, ,    ).   ,     :

1)     ,      ,   80%    .  ,      ,      .  ,         ,    ,   ,   .

2)      . ,  ,   ,     ,  ,  .

3)    ,           .          ,   ,        ,     .

           :     ,     ,     .     ,      .      ,     .    :        ,     .

   ,       ,    ,             R.  ,        (   ).   ,       ,     ,     ,        .  ,   ,       ,             1-2 .  ,            1.        ( 10-100  ),           .         ,     ,   .       ,              .

   ,  ,            .      ,  ,      , . ,  ,   ,            .     ,     ,     .     ,            ,  ,    . ,       ,     .             .    ,     10  100 ,       .  ,         ,    (, Hadoop  Spark),           .  ,                  ,   ,       .

,        Python, Julia     ,    .   ,    , .        ,     R  Python. ,      .    ,    ,             .    ,      ,   ,   ,   ,         .            -.

, R           .  R     ,          .    , R     ,      .     ,     ,            .   -        ,        .

     :  ,        .  ,     ,        , , , ,   .        ,        .

       :      (   ).           .              ,    ,      .    , ,     .

         .       :

1)      ,    .        .

2)         .     ,   ,     .  ,    ,      ,     .      ,   ,   .

                .      ,          .     ,     :    ,  ;  ,   ,   .

      ,               .     ,      ,      .

        : R, RStudio,   R   Tidyverse    .       R.     , ,    .

  R,     ,    CRAN,     ,    ,     R.    ,    ,     , https://cloud.r-project.org,        .

   R     ,  ,        .      . ,     ,   ,      ,     .

RStudio    ,  IDE,    R.        http://www.rstudio.com/download. RStudio     .     , RStudio   .  ,      ,     .      , ,     RStudio.

  RStudio,    :








   ,   ,  ,   R    ,       Enter.

 ,    :

library(ggplot2)

ggplot(mpg, aes(x = displ, y = hwy))+geom_point(aes(colour = class))

   








      (ggplot2)       ,   (displ)        ,     (hwy)      (mpg)      (class).

         .








      R.  R    ,   ,     .        R.  ,            Tidyverse.  Tidyverse        R,      .      Tidyverse   :

install.packages("tidyverse")

       ,     Enter,   . R      CRAN     .     , ,     ,   https://cloud.r-project.org/         -.

    ,      ,        library().        :

library(tidyverse)

       ,   tidyverse,        .

 tidyverse   .  ,   ,     , 

tidyverse_update()

   ,     tidyverse,        ,        .       ,   .     R,          .          -  tidyverse.         ,    ,      , ,    ,             .

         R.     :

1 + 2

#[1] 3

        ,    :

> 1 + 2

[1] 3

 ,      ,  >,      .        #;       .    ,       ,            .  ,           :

1)        ,  sum().

2)   R, ,    ,   .

3)     ,     ,     ,        .     R.

  ,       ,     -,   R.     ,       ,   ,     .   ,   ,   .   ,   ,   Yandex.  ,  R   ,     :    ,   ,     R ,  Yandex       .        Yandex   ,   ,  .  , -     ,     -  .        ,    

Sys.setenv(LANGUAGE = "ru")

   ;           .  ,      ,     ,   RStudio   Tools/Global Options   UTF-8     ,      :








 Yandex  ,   ru.stackoverflow.com.   ,        ,      [R],       ,   R.     ,      .         ,     ,        .

  ,   ,      :  ,    .

1)       ,    ,      .  ,     ,      ; ,             .     tidyverse      tidyverse_update().

2)        ,   dput ()    R. ,     mtcars  R,    :

) dput (mtcars)  R

)  

)    mtcars<    .      ,     .

3)     ,  ,       .  : ,        ,  ;  ,  ,    ;   ,   ,      .    ,    , ,     .

4) , ,          R,      .

  ,      ,        .     R       .          RStudio,      ,          .         R    ,   http://www.r-bloggers.com:    700   R   .       Twitter,       #rstats,   Twitter     ,     R.            R,       .   ,           ,           ,     https://www.researchgate.net.




2.    


     ,         .           ,   ,   ,      ,  .       ,       ,     .

       ,       :

1)       R,    ,      ,     .        ggplot2,         .

2)    ,  ,      ,            ,   ,       .

3) ,    ,          ,         .

     ,     ,       .   ,           .

  ,     ,    .       ,  ,           R-.       ,        .

    ,        ,     . ,      ggplot2.  R      ,  ggplot2        ,   ggplot2   ,       .  ggplot2,   ,           .

       ggplot2,  ,  ,        .       ggplot2,       tidyverse.     ,   ,       ,  tidyverse      :

library(tidyverse)

      tidyverse, ,        .      ,    tidyverse      R (   ,    ).          library(tidyverse) :    tidyverse,      ,     library()  :

install.packages("tidyverse")

library(tidyverse)

   ,      ,     .            (  ),        , , ggplot2::ggplot()   ,     ggplot()   ggplot2.       ,    a :        ,     ?  :        - ,          ? , ,   ,   .        ,      ,    ,      ,   : ? ? ? ?

         mpg   ggplot2 (  ggplot2::mpg).       ( )    ( ).  mpg  ,        38  .

     mpg :

1. displ,   ,  ;

2. hwy,     ,     (mpg).

       ,      ,        .      mpg,     .

  mpg,   ,   displ   x  hwy   y:

ggplot (data = mpg) +

geom_point (mapping = aes (x = displ, y = hwy))

         (displ)    (hwy).  ,       ,             .             ?

  ggplot2        ggplot(). ggplot()   ,    .    ggplot()   ,   .  , ggplot(data=mpg)   ,     .    ,       ggplot().  geom_point()   .

  , ggplot2      geom,        ,        .

  geom  ggplot2  ,  ,         .  mapping     aes(),   x  y   aes () ,      x  y . ggplot2      , ,   mpg.

           ggplot2.   ,             ,  geom,     :

ggplot(data = <>) +

< geom>(mapping = aes(< geom ><>))

   ,      ,     .    <>.



1. ggplot(data=mpg).  ?

2.    mpg?   ?

3.   drv?    mpg,    ?mpg,   .

4.   hwy  cyl.

5. ,       class  drv?     ?

   ,   ,       ,      .        (      2-Seater, )   ,       .      ,     .   ?  ,     .            class   .  class    mpg     ,  compact, midsize  SUV.      ,       , ,  (  ,       ,       ).

   ,  class,       .         .      ,  ,    .           .        ""    ,     ""   , ,  .    ,    ,    ,   .

 ,                 . ,     (color)     (class),     .  ,  x = displ, y = hwy     aes()     color = class.

     ,    ,   (color),     aes(). ggplot2         ,    ,     .

 ,        .      ,  ,  ,   .     ,     ,   ,      ,    .  ,     ,       .

       ,          .          .    color = class  size = class,      ,      (class)     (size)    .

#> :   size     .

 ,        (alpha),     (shape).     color = class  alpha = class,   shape = class .     ggplot2       ,       .

    aes(),         .  aes()      ,         .       x  y:   x  y,      ,  ,        .  ,   , ggplot2    .     ,  ,    .    x  y  ggplot2   ,         .         ,          .

      geom , ,       ,    :

geom_point(mapping = aes(x = displ, y = hwy), color = "green")

      ,      .   ,     .  ,      , , 0, 15  22   ,      ,     .   (0-14)  ,    color;   (15-18)     color;   (21-24)  ,    .



1.      ?

2.    mpg  ?    ? (:        mpg).         mpg?

3.    ,   .             ?

4. ,          ?

5.   stroke?     ? (:     geom_point,       ?geom_point)

6. ,     - ,    ,  color = displ < 5?          x  y.

    R,   .  ,    .      R,    ,    .     ,  ,    . R  . ,     (  ),    "   ".   ,    .      :   +,  ,  R   ,     ,     .       ,   ESC,     .

     ggplot2   +  ,      ,    . ,     .     ,     .        R    ?_  ,         F1  RStudio.  ,    ,          ,   ,   .     ,      .     .     R,       ,     .      Yandex,       ,   ,  -   ,       -.

   ,        ,     .     ,     ,     , ,          .

          ,  facet_wrap().    facet_wrap()       R,     ~,     . ,    facet_wrap(),   . ,  :

ggplot(data = mpg) +

geom_point(mapping = aes(x = displ, y = hwy)) +

facet_wrap(~ class, nrow = 1)

          ,    ,    nrow = 1:








      ,      ,   facet_grid()   .             ,   ~:

ggplot(data = mpg) +

geom_point(mapping = aes(x = displ, y = hwy)) +

facet_grid(drv ~ cyl)

       ,   ,   ,    .    . ,   +facet_grid(cyl ~ .)    ,     .



1. ,       ?

2.       facet_grid(drv~cyl)?

3.              ?   ?            ?

4.   ?facet_wrap.    nrow, ncol?     ?   facet_grid()    nrow  ncol?

5.  facet_grid()          . ?

     .       ,      :

My_table < structure(list( = c("7", "7", "7", "7", "7", "7", "7", "7", "7",

"7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "", ""),

` ` = c(" ", " ", " ", " ",

" ", " ", " ", " ",

" ", " ", " ", " ",

" ", " ", " ",

" ", " ", " ", " ",

" ", " ", " "), 1 = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1), 2 = c(2, 3, 3, 2, 2, 3, 3, 2, 2, 3, 4, 5, 5, 4, 4, 4, 5, 5, 4, 5, 5, 1), 3 = c(1, 2, 2, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 1, 2, 5, 1), 4 = c(4, 5, 5, 4, 4, 4, 5, 5, 5, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 4, 5, 1), ` 5` = c(1, 2, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 5, 5, 1), `` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)),

row.names = c(NA, -22L), class = c("tbl_df", "tbl", "data.frame"))

  :















    ?

        x,     y,       .     .          .   ggplot2      (geom). Geom    ,      . ,      ,          .     ,     .   ,            .      ,      ,  .       ,   geom_,    ggplot (). ,    ,  :

#  

ggplot (data = My_table) +

geom_point (mapping = aes (x = ``, y = 2))

#  

ggplot (data = My_table) +

geom_smooth (mapping = aes (x = ``, y = 2))

  geom  ggplot2   mapping,          geom.      ,     .   ,    linetype,  geom_smooth()         ,     .

,  geom_smooth()     :

ggplot (data = My_table) +

geom_smooth (mapping = aes (x = ``, y = 2, linetype = ))

      2     7,    7:








  , ,                  . ,       geom_  ,              .

ggplot2   40   geom_,      .     ,  : ?geom_smooth.

   geom_,   geom_smooth(), ,         .   ,              ,   ggplot2          .   ggplot2         ,       (     linetype).    ,            ,           .  ,     ,    show.legend = FALSE,       :

ggplot (data = My_table) + geom_smooth (mapping = aes (x = ``, y = 2))

ggplot (data = My_table) +

geom_smooth (mapping = aes (x = ``, y = 2, group = ))

ggplot (data = My_table) +

geom_smooth( mapping = aes(x = ``, y = 2, color = ),

show.legend = FALSE)

      ,     geom  ggplot():

ggplot (data = My_table) +

geom_point (mapping = aes (x = ``, y = 2)) +

geom_smooth (mapping = aes (x = ``, y = 2))

, ,     . ,     y      3   2,       ,          .

   ,    mapping     ggplot(). ggplot2              .  ,      ,   ,   :

ggplot (data = My_table, mapping = aes (x = ``, y = 2)) +

geom_point() + geom_smooth()

    mapping    geom,  ggplot2        .    mapping       .        :

ggplot (data = My_table, mapping = aes (x = ``, y = 2)) +

geom_point (mapping = aes (color = )) + geom_smooth()








   ,       :

ggplot (data = My_table, mapping = aes (x = ``, y = 2)) +

geom_point (mapping = aes (color = )) +

geom_smooth (data = My_table[My_table$ == "7", ], se = FALSE)








  ,        .    geom_smooth()       ggplot().

     ,     ,       7 ,   se = FALSE    .



1.    geom_       ?   ,  , ?

2.   show.legend = FALSE?     ?  ,      ?

3.   se   geom_smooth ()?

4.  R,          :








   ,    .   ,   ,       .    ,       geom_bar().   ,     (1833-1899)  -   :    ,      , ,       -        .           ,      ggplot2  ,   .

    (diamonds)    ggplot2     ~54000  ,  ,   , ,      . , -   .  ,        ,    :

ggplot (data = diamonds) +

geom_bar (mapping = aes (x = cut, colour = diamonds$color))








  x    (cut) .   y        (count),        count.      ?   ,   ,        . ,  ,      . ,   ,   ,      ,     .         ,      .           . ,       ,   stat,    .    ,     geom_bar().   ,        ,      stat. ,     ?geom_bar ,        stat  count,   geom_bar()   stat_count(),     ,   geom_bar(),    ,      ,   ,      : count  prop.

 ,  geom_  stat_ . ,       stat_count()  geom_bar().  ,      geom_   stat  ,     stat_    geom  .  ,      ,          .   ,       stat   :

1) ,       .   ,    stat  geom_bar()  count (  )  identity.         .     ,      ,        ,   ,        .








 .

 ,          5-,    1837      . ,                   .

library(tidyverse)

demo < tribble( ~, ~,

"", 1,

"", 1,

"", 3,

"", 2,

"", 3 )

ggplot(data = demo) +

geom_bar(mapping = aes(x = , y = ), stat = "identity")








 ,    < tribble .      ,        ,     .

2) ,        . ,      ,   :

library(tidyverse)

demo < tribble( ~, "", "",

"", "", "",

"", "",

"", "", "" )

ggplot (data = demo) +

geom_bar (mapping = aes (x = , y = stat (prop), group = 1))








    ,   ,     ,    .

3) ,        . ,    stat_summary(),      ,     .           7  7    2,      ,    .          :

ggplot(data = My_table[My_table$ == "7" |My_table$ == "7",]) +

stat_summary(

mapping = aes(x = , y = 2),

fun.ymin = min,

fun.ymax = max,

fun.y = median

)








    ,  ggplot2    20 .    stat  ,        , ,  ?stat_bin  .



1.  geom  ,   stat_summary()?     ,      geom_  stat_?

2.   geom_col()?     geom_bar()?

3.   geom  stat ,     .        ,    ?

4.     stat_smooth()?     ?

5.       group = 1. ?  ,       ?

    ,   .        ,      (color)   (fill).  ,  ,       :          .

      (position).    ,    ,        :    (identity),    (dodge)        (fill).  position = "identity"      ,      .        ,           .    ,    ,    (alpha)  ,    fill = NA.      2d-,   .  position = "fill"   ,        .        .   position = "dodge"        ,     .

        ,        .     .   ,     126 ,        234 .        :  11           59,  60,  58.      ???.     ,   x  y .  ,        .     overplotting.       ,      .        ,     x  y,   109  ?   ,       (jitter).  position = "jitter"        .           , , ,     .       ,    ,        ,       .     ,  ggplot2       geom_point(position = "jitter"),     geom_jitter().

     ,    ,     .



1.   geom_jitter()   ?

2. geom_jitter()  geom_count(),   .

3.      geom_boxplot()  ?        .

          .  , ,      ggplot2. ,       ,    x  y      .      ,   .  coord_flip()    x  y.  ,      ,     ,        x.

#  

ggplot(data = My_table[My_table$ == "7" |My_table$ == "7",],

mapping = aes(x = , y = 2)) +

geom_boxplot()

#  

ggplot(data = My_table[My_table$ == "7" |My_table$ == "7",],

mapping = aes(x = , y = 2)) +

geom_boxplot() +

coord_flip()















 coord_quickmap()      .   ,        ggplot2. :

1)   ,     .

install.packages("maps")

2)   .

library(maps)

3)    .

ru < map_data("world")

4)        

ggplot(ru, aes(long, lat, group = group)) +

geom_polygon(alpha=1/5, fill = "green", color = "black") +

coord_quickmap()








 coord_polar()      .           .    ,   ,        .     bar        . ,  ,      ,       :

bar < ggplot(data = diamonds) +

geom_bar(

mapping = aes(x = cut, fill = cut),

show.legend = FALSE,

width = 1

) +

theme(aspect.ratio = 1) +

labs(x = NULL, y = NULL)

bar + coord_flip()

bar + coord_polar()

















1.          coord_polar().

2.     labs()?   .

3.    coord_quickmap()  coord_map()?

4.   coord_fixed()?    geom_abline()?

5.       .

      ,   -.      ,      ggplot2  .   ,   ,  ,          :

ggplot(data = <>) +

<geom_  >(

mapping = aes(<     >),

stat = <  >,

position = <  >

) +

<  > +

<  >

     (   ),       .       ,   ,    ggplot2         ,       geom.

      ,    .     ,           ,  ,  ,  ,    ,        .

 ,   , ,       :   ,        . ,         .       ,       ,        .    ,       ,        ,     x  y.    ,          ( )      ().     ,      ,        ,  ,  ,      .

        .  ,          .

   ,    . ,     ,             .        ,       ,          . ,       ,       dplyr       ,   -.




 .       -25     ,  1939 ,      -  1939-1940 . -, .

  ,    dplyr,     tidyverse.   ,     nycflights13,   ggplot2,    .

library(nycflights13)

library(tidyverse)

      ,     tidyverse,   dplyr    R.        dplyr,          , , stats::filter().

        dplyr,     nycflights13::flights,      336776 ,   -.       ,         ,    :

flights

,               ,   .       ,    .     ,  :

view(flights)

    RStudio,    ,      tidyverse.        ,         .            : int   ; dbl   ; chr   ; dttm  - ( + ).      ,      ,    : lgl   ,    TRUE  FALSE; fctr  ,  R         ; date  .

    dplyr       : filter()     ; arrange()   ; select()     ; mutate()       ; summary()     .       group_by(),             .           .

     :

1)     .

2)   ,      ,     ,      ',      .

3)     .

             .   ,   . filter()        .      .      ,  . ,     5   :

filter(flights, month == 5, day == 5)

    , dplyr        .  dplyr    , ,    ,     :

may5 < filter(flights, month == 5, day == 5)

R   ,     .     ,  ,     :

(may5 < filter(flights, month == 5, day == 5))

   ,  ,   ,   . R    : > (), >= (  ), < (), <= (  ), != (), == ().   R   =  ==   .   ,     .     ,      ==,     .   :

sqrt (4) ^ 2 == 4

# > [1] TRUE

sqrt (5) ^ 2 == 5

# > [1] FALSE

1 / 50 * 50 == 1

# > [1] TRUE

1 / 49 * 49 == 1

# > [1] FALSE

  ,   R    ,       ,    .     R  ,    ==    near(),    :

near(sqrt(5) ^ 2, 5)

# > [1] TRUE

   filter()        ,  ,     ,           .        : &  , |  , !   , xor(x,y)      x,y.

    ,      :

filter(flights, month == 2 | month == 3)

    

filter(flights, month == (2|3))

           2|3,     TRUE.    TRUE    1,      ,     .

        x %in% y.     ,  x      y.         :

filter(flights, month %in% c(2, 3))

            : !(x & y) == ! | !y,  !(x | y) == !x & !y. ,    ,    (   )    ,      :

filter(flights,!(arr_delay > 60 | dep_delay > 60))

filter(flights, arr_delay <= 60, dep_delay <= 60)

 &  |,  R  &&  ||,     ,  ,      .

 ,       filter(),      ,      .  ,     .    R,    ,   ,   (NA),     ,     ,      NA   NA.

NA > 1

#> [1] NA

2 == NA

#> [1] NA

NA + 3

#> [1] NA

NA / 4

#> [1] NA

     :

NA == NA

#> [1] NA

      :     ,    ?   !   ,     ,    is.na(),      .  filter()    ,      TRUE,      FALSE,   NA.     ,      :

filter (flights, is.na(month) | month > 1)



1.  , :        ;   ;   Delta;  ;        ;      ,    30   ;     6  ().

2. between()   dplyr    .    ?       ,       ?

3.     dep_time?      ?         ?

4.  NA^0 , NA/TRUE  ,  FALSE&NA ?     ,    NA*0?

 arrange ()    filter(),   ,    ,  .         (   ),      .      ,              :

arrange(flights, year, month, day)

 desc()         :

arrange(flights, desc(dep_delay))

  (NA)     .



1.   arrange()        ? (:  is.na()).

2.      .  ,    .

3.  ,     .

4.    ?     ?

         .         .  select()      ,      . , select()      ,     19 ,    :

#    , 

select(flights, month, day)

#        

select(flights, month:day)

#   ,  ,       

select(flights, -(month:day))

  ,     select():  starts_with("")      ;  ends_with("")      ;  contains("")     ;  matches("(.)\\1")  ,      ,        ,   ,          ;  num_range("m", 2:4)   m2, m3, m4.     ?select     .

 , select()     ,      ,       .       rename(),    select(),    ,    :

rename(flights,  = year)

   select(),     everything(),      ,       . ,  (month)   (day)         ,      (flights)  :

select (flights, month, day, everything ())

      (time_hour),  ,   ,    (air_time)    .



1.  ,                 flights.

2. ,           select()?

3.   one_of()?         c("month", "day")?

4.      ?          ?      ?

select(flights, -contains("TIME"))

   ,    , ,     ,   ,    .       mutate(),          .      ,    . ,   RStudio           view().  __,      (year)   (day) ,  ,     (  delay),   (distance)    (air_time)  :

__ < select(flights,

year:day,

ends_with("delay"),

distance,

air_time)

       ,     ,  ,     .  ,     ,   .       ,   transmute()  mutate():

mutate(__,

 = dep_delay  arr_delay,

 = distance / air_time * 60,

_= air_time / 60,

___ =  / _ )

      ,     mutate().      ,        ,                   .      ,      .

 : +, -, *, /, ^.          ,   ,      ,              .  ,      .       _    ,      .         ,    . , x/sum(x)       ,  ymean(y)     .

 : %/% ( )  %% (),  x==y*(x%/%y)+(x%%y).     ,          . ,    flights           ,       (dep_time).           ,         :

transmute(flights,

dep_time,

 = dep_time %/% 100,

 = dep_time %% 100)

 : log(), log2(), log10(),        ,       .       ,      ,  .    ,    log2()      :   1        ,    -1   .

:  lead()   lag()       .     , , lag(x),     ,  x!=lag(x).       group_by(),     .

   : R       cumsum(),  cumprod(),  cummin()   cummax()  ;  , dplyr   cummean()    .    ,      ,      RcppRoll.

 : < (), <= ( ), > (), >= ( ), != ( ),  == (),     .  ,      ,          ,        .

:      ,   min_rank(),       (, 1-, 2-, 3-, 4-).       ,     desc()     ,          .  min_rank()   ,  ,             .



1. ,   ,  ,      ,       ,  159 (  1 , 59 )   200 (2  ).      ,        .

2.  _  ___.      ?   ,   ?

3. 10   ,   .   ?      min_rank().

4.  2:4  5:8  ?

5.     R?

   summary(),          . ,   (mean)  dep_delay    __:

summarise(flights, __ = mean(dep_delay, na.rm = TRUE))

  ,     na.rm = TRUE.  summary()   ,      group_by(),          .      dplyr   ,   group_by()          . ,          ,      ,        :

__ < group_by(flights, year, month, day)

summarise(__,

____ = mean(dep_delay, na.rm = TRUE))

  group_by()   summary()        dplyr      .  ,    ,     ,         . ,              .       dplyr,      :

____ < group_by(flights, dest)

 < summarise(____,

 = n(), __ = mean(distance, na.rm = TRUE),

_ = mean(arr_delay, na.rm = TRUE))

         , ,    :

 < filter(,  > 100, dest != "MSK")

  :

ggplot(data = , mapping =

aes(x = __, y = _)) +

geom_point(aes(size = ), alpha = 1/5) +

geom_smooth(se = FALSE)








,        ~750 ,   . ,    ,       ?

       :

1.   .

2.     ,       .

3.   ,     .

   ,        .   ,         ,   .                %>%:

 < flights %>%

group_by(dest) %>%

summarise(

 = n(),

__ = mean(distance, na.rm = TRUE),

_ = mean(arr_delay, na.rm = TRUE) ) %>%

filter( > 100, dest != " MSK ")

       ,    ,       ,     .     : ,    ,    .    ,   %>%     .   ,               . , x%>%f(y)   f(x, y),  x%>%f(y)%>%g(z)    g(f(x,y),z)   ,          ,     ,  .    ,       ,       .

        tidyverse.    ggplot2,           R.  ,   ggplot2  ggvis      ,       .

          na.rm.  ,    ?    !   ,        :     -  ,     .  ,      na.rm,       .   ,      ,       ,    .    ,         :

 < flights %>%

filter(!is.na(dep_delay), !is.na(arr_delay))

                :

 %>%

group_by(year, month, day) %>%

summarise(_ = mean(dep_delay))

 ,    ,           n(),        sum(!is.na(x)).    ,           . ,     ,    tailnum    ,           :

 <  %>%

group_by(tailnum) %>%

summarise(

_ = mean(arr_delay)

)

ggplot(data = , mapping = aes(x = _)) +

geom_freqpoly(binwidth = 5)








        5  (300+ )?       ,      .       ,         :

 <  %>%

group_by(tailnum) %>%

summarise(

_ = mean(arr_delay, na.rm = TRUE),

__ = n()

)

ggplot(data = , mapping = aes(x = __,

y = _)) +

geom_point(alpha = 1/15)








,        ,      ,   .  ,        :  ,     (  )     ,   ,          .

 ,    ,       ,             .          ggplot2    dplyr.       %>%  +,  ,     .          ,   33:

 %>% filter(__ > 33) %>%

ggplot(mapping = aes(x = __,

y = _)) +

geom_point(alpha = 1/15)








   RStudio  Ctrl+Shift+P,          .   ,      33    :       Ctrl+Enter,           Ctrl+Shift+P,       .

        .        ,     .     Lahman      (  /  )     .




 .        ,         ,   ,   ,      ,   300     ,        20 .

      ,              ,    :

1.     ,       .

2.           .   ,     ,  ,         .

        ,    :

 < as_tibble(Lahman::Batting)

 <  %>%

group_by(playerID) %>%

summarise(

 = sum(H, na.rm = TRUE) / sum(AB, na.rm = TRUE),

 = sum(AB, na.rm = TRUE)

)

 %>%

filter( > 100) %>%

ggplot(mapping = aes(x = , y = )) +

geom_point() +

geom_smooth(se = FALSE)

 geom_smooth()            (method = "gam")     formula = y ~ s(x, bs = "cs"),     1000 .








    .        ,         ,    ,      1 ,      :

 %>%

arrange(desc())

         .   ,    ,  ,     ,  R          :

  ,    mean(x),      median(x)   .    36.6  ,     ,   50%  x  ,  50%  ,   .        .          ,     ,     ,     ,    .

        , ,   :

 %>% group_by(year, month, day) %>%

summarise(

_ = mean(arr_delay),

__ = mean(arr_delay[arr_delay > 0])

)

       sd(x),    ,    IQR(x)      mad(x),          ,     . ,        ,   ,       :

 %>% group_by(dest) %>%

summarise(__ = sd(distance)) %>%

arrange(desc(__))

    min(x),   quantile(x, 0.25),   max(x),     .    . , , quantile(x, 0.25)   x,    25%       ,     75%.

        :

 %>% group_by (year, month, day) %>%

summarise( _ = min (dep_time),

_ = max (dep_time) )

        first(x)      x, nth(x, n)   n-, last(x)   .        x[1], x[n]  x[length(x)],     default,     . ,        ,  $dep_time[length($dep_time)+1],  NA,   ,       !  nth($dep_time,length($dep_time)+1, default = "!").

  range()  .  ,          ,       ,        .  ,   range($dep_time)  ,        dep_time:

 %>% group_by (year, month, day) %>%

mutate( = min_rank(desc(dep_time))) %>%

filter( %in% range() )

      n(),    ,     .        ,   sum(!is.na(x)),      ()   n_distinct(x). , ,      :

 %>% group_by(dest) %>%

summarise(= n_distinct(carrier)) %>%

arrange(desc())

   ,    dplyr    count()  .     ,    dest   :

 %>% count(dest)

       (wt). ,         ,       ,    talinum    :

 %>% count(tailnum, wt = distance)

     , sum(x>777),    , mean(y == 0), ,       TRUE   1,  FALSE  0.    sum()  mean()  : sum(x)    TRUE   x,  mean(x)   . ,      6      ,        :

 %>% group_by(year, month, day) %>%

summarise(_ = sum(dep_time < 600))

   ,   :

 %>% group_by(year, month, day) %>%

summarise(_ = mean(arr_delay >= 61))

    ,        .       :

__ < group_by(flights, year, month, day)

(__ < summarise(__,  = n()))

(__ < summarise(__,  = sum()))

(__ < summarise(__,  = sum()))

     ,       ,       ,    ,        .  ,      ,         ,             .    ,       ,    ungroup():

__ %>%

ungroup() %>% #   

summarise( = n()) #   



1.       7        ,   :

) 50%     15   ,   50%    15 .

)    10 .

)50%    30  ,  50%  30  .

) 99%      ,    1%    2 .

    ,     ,    ?

2.      ,      %>% count (dest),  %>% count(tailnum, wt = distance),     count().

3.     :

 < flights %>%

filter( is.na(dep_delay) | is.na(arr_delay) )

?      :    (dep_delay)     (arr_delay)?

4.     .    ?        ?

5.  (carrier)      ?            ?  ,  ,  ,  ?

6.       sort   count()?    ?

          summarise(),         mutate()   filter().   __ < select(flights, year:day, ends_with("delay"), distance, air_time),     ,    5       :

__ %>% group_by(year, month, day) %>%

filter(rank(desc(arr_delay)) <= 5)

        ,      :

( _ < flights %>% group_by(dest) %>%

filter(n() > 17282) )

           :

_ %>% filter(arr_delay > 0) %>%

mutate(_ = arr_delay / sum(arr_delay)) %>%

select(year:day, dest, arr_delay, _)

 ,     ,     .   ,     ,         . ,       ,  mutate()  filter(),   ,       summary().          ,    vignette("window-functions").



1.     mutate()  filter()  .          ?

2.  ( )     ?

3.     ,    ?

4.       .          .

5.    :         ,    ,     .    lag() ,         .

6.   .    ,   ?    ,       .             .        ?

7.   ,        .      .

8.          1.




3.   


        R,    ,  ,    ,       .  ,     R,       ,              .       ,   ,        ,    ,    ,     R.     ,        R,         RStudio.     ,           . -,   R   :

2*2

#> [1] 4

sin(pi/2)

#> [1] 1

     ,           :

(-1)^(1/2)

#> [1] NaN

(-1+0i)^(1/2)

#> [1] 0+1i

       <-:

x < 2*2

  R,     ,   :

_ < _

        :  _   _.       ,     .  ,   =,    ,     .      RStudio: Alt +  ( )    <-.  ,  RStudio   < .     ,  ,  .

          , ,   _  .,   ,     ,       .   _,        _.

,

._.

   ,     .  ,      ,   :

x

#> [1] 4

 , :

___ < 777

    ,   RStudio   :     Tab,  Ctrl+Space (),   ,      ,     Enter.  ,  ___     1234,   777.     ,   .    Ctrl + ?.      ,     .      Enter,    .        777  1234   .

   ,   



#> :  ''  

X

#> :  'X'  

      R:       ,  ,       .  ,    .

R     ,   :

_(1 = 1, 2 = 2, )

    seq(),     ,         RStudio.  se   Tab.     .  seq(),   q,   ,    ?/?     .     ,        .    ,    F1,             .   Tab  ,   ,   . RStudio    (  ) .   1, 5   Enter.

seq(1, 5)

#> [1] 1 2 3 4 5

    ,  RStudio    :

x < " !"

  ,          . RStudio   ,     .   - ,  R :

> x >

+

 +   ,   R   .   ,     ",   ).   ,    Esc,    .

       ,    ,    :

y < seq(1, 5, length.out = 4)

y

#> [1] 1.000000 2.333333 3.666667 5.000000

         :

(y < seq(1, 5, length.out = 4))

#> [1] 1.000000 2.333333 3.666667 5.000000

         RStudio:








    ,    .



1.    :

label < 1

lbel

# > :  'lbel'  

    ?  !   ,     a-  -  R .

2.  Alt + Shift + K ().  ?          ?

       .    ,       ,       ggplot2       dplyr.     ,    .  ,    File,   New File  R Script,      Ctrl+Shift+N.   :








        .    ,     ,     ,  ,     . RStudio              .   ,    ,    .

          ggplot2     dplyr.             .       RStudio  Ctrl+Enter,     R  . ,      .      ,   Ctrl+Enter          .       ,    Ctrl+Enter.

 ,      ,     ,  Ctrl+Shift+S.    ,  ,      .           .  ,      ,     ,      .          install.packages()     setwd()   ,         .

                .           ,       .

   ,            .     ,  ,   . RStudio      .



1.  ,   .    .

2.    RStudio   ?

              .     R   ,       .       ,     R    .  ,   R               .      ,       :

1.    ,           ?

2.  ?

   R    RStudio     R,         .         R-.   R-         ,       R-.       ,    ,        R.   RStudio ,       ,     ,   ,   RStudio,    ,     .       ,              .   ,              RStudio,    .

   ,           RStudio:

1. Ctrl+Shift+F10,    RStudio.

2. Ctrl+ Shift+S,      .

 R    .        ,    ,    . RStudio         .       ,    R  getwd().   R       ,  ,       .                     R   .       R   setwd("/////").     ,    ,    R      .      ,     Mac, Linux  Windows      .    :

1)        . Mac  Linux    /,  Windows     \. R      ,    ,         ,  ,      ,         .      Linux/Mac      /.

2)  ,   ,     ,    ,  -.  Windows     ,  C:,      , , \\_,   Mac/Linux      /, , /users/RStudio.       ,          ,          .

3)       .  ~      ,   Windows       ,  ~      .

   ,      ( , R ,  , )   .      ,   RStudio         .

   ,         ,        File,   New Project.       ,     .     ,       .     , ,         .  ,         ,      .

      

library(tidyverse)

ggplot(diamonds, aes(carat, price)) +

geom_hex()

ggsave(".pdf")

write_csv(diamonds, ".csv")

  ,   .R. ,   ,    PDF  CSV   .    ,     .  ,   RStudio    ,        .Rproj.        . ,    ,  ,         ,   ,   .     ,         ,   .

     .pdf,   PDF   ,    (.R).     ,    .     R,         ,    .

 RStudio     .       :

    RStudio    .

      ,      R.

     ,  ,     .

       (,  ).

    ,   .

 ,         ,    .




4.   


        ,     ,     .    ,    ,      ,       :

1)     .

2)     ,   .

3)   ,       .

        ,    .        ,    ,    .     ,    ,    ,         ,          .

        ,         ,      .       .    ,       .     ,     : ,   .

   dplyr  ggplot2      ,  ,     , ,            ,         .        ,     .              .  ,           ,  ,    .      (   )     .      ,   ,    ,      .            ,      . ,      ,     ,    ,       .   ,   ,  ,           .        ,   ,     ,    .

   ,    ,    .   ,        :

1)     ?

2)     ?

    .  ,     ,        .    ,   :

   ,   ,   .

    ,    .      .

    ,    .           .     ,       ,        .

     ,        .          ,       ,      .

    ,  ,  ,         , , , , ,          .

                .        .      ,     ,    ,  ,   .        ,     .            (,     ),     (,       ).      ,     .            .

       ,      .   ,          .  R         .        ,    ,        .   ,            .           .        ,       .   ,     x   ,         ,       .        binwidth,       x.        binwidths    ,        .        ,     geom_freqpoly()  geom_histogram(),   geom_freqpoly()     ,    geom_histogram(),         .    ,     ,   .

          2     2  :

ggplot(data = filter(My_table,  %in% c("7","7")),

mapping = aes(x = 2, colour = )) +

geom_freqpoly(binwidth = 0.5)








  ,    ,     ,       .  ,  ,     ,     ?   ?

    ,       ,        .     ,    (    ?)   (     ?).




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=57427114)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


