R数据科学练习题:第二章 练习 (1)为什么以下代码不能正常运行? my_variable <- 10 my_varjable #> Error in eval(expr, envir, enclos); #> object 'my_varjable' not found 答案:因为我把字母输错了,仔细看。(书中的那个符号用j代替了) (2)修改以下代码,使其可以正常运行。 library(tidyverse)
ggplot(dota = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) fliter(mpg, cyl = 8) filter(diamond, carat > 3) library(tidyverse) ## ─ Attaching packages ─────────────────── tidyverse 1.3.0 ─ ## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4 ## ✓ tibble 3.0.3 ✓ dplyr 1.0.1 ## ✓ tidyr 1.1.1 ✓ stringr 1.4.0 ## ✓ readr 1.3.1 ✓ forcats 0.5.0 ## ─ Conflicts ──────────────────── tidyverse_conflicts() ─ ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) # data not dota
filter(mpg, cyl == 8) # "==" not "=" ## # A tibble: 70 x 11 ## manufacturer model displ year cyl trans drv cty hwy fl class ## ## 1 audi a6 quatt… 4.2 2008 8 auto(… 4 16 23 p mids… ## 2 chevrolet c1500 su… 5.3 2008 8 auto(… r 14 20 r suv ## 3 chevrolet c1500 su… 5.3 2008 8 auto(… r 11 15 e suv ## 4 chevrolet c1500 su… 5.3 2008 8 auto(… r 14 20 r suv ## 5 chevrolet c1500 su… 5.7 1999 8 auto(… r 13 17 r suv ## 6 chevrolet c1500 su… 6 2008 8 auto(… r 12 17 r suv ## 7 chevrolet corvette 5.7 1999 8 manua… r 16 26 p 2sea… ## 8 chevrolet corvette 5.7 1999 8 auto(… r 15 23 p 2sea… ## 9 chevrolet corvette 6.2 2008 8 manua… r 16 26 p 2sea… ## 10 chevrolet corvette 6.2 2008 8 auto(… r 15 25 p 2sea… ## # … with 60 more rows filter(diamonds, carat > 3) # diamonds not diamond ## # A tibble: 32 x 10 ## carat cut color clarity depth table price x y z ## ## 1 3.01 Premium I I1 62.7 58 8040 9.1 8.97 5.67 ## 2 3.11 Fair J I1 65.9 57 9823 9.15 9.02 5.98 ## 3 3.01 Premium F I1 62.2 56 9925 9.24 9.13 5.73 ## 4 3.05 Premium E I1 60.9 58 10453 9.26 9.25 5.66 ## 5 3.02 Fair I I1 65.2 56 10577 9.11 9.02 5.91 ## 6 3.01 Fair H I1 56.1 62 10761 9.54 9.38 5.31 ## 7 3.65 Fair H I1 67.1 53 11668 9.53 9.48 6.38 ## 8 3.24 Premium H I1 62.1 58 12300 9.44 9.4 5.85 ## 9 3.22 Ideal I I1 62.6 55 12545 9.49 9.42 5.92 ## 10 3.5 Ideal H I1 62.8 57 12587 9.65 9.59 6.03 ## # … with 22 more rows (3)按Alt + Shift + K组合键会发生什么情况?如何使用菜单完成同样的操作? 自己试试,或者关注茶与生信公众号,你将找到详细解答。 ##其实第二章将最多的是:细心,认真
|