R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(tidyverse) -- Attaching packages --------------------------------------- tidyverse 1.2.1 -- ggplot2 3.0.0 purrr 0.2.5 tibble 1.4.2 dplyr 0.7.6 tidyr 0.8.1 stringr 1.3.1 readr 1.1.1 forcats 0.3.0 -- Conflicts ------------------------------------------ tidyverse_conflicts() -- x dplyr::filter() masks stats::filter() x dplyr::lag() masks stats::lag() > 3+2 [1] 5 > 2**5 [1] 32 > sqrt(25) [1] 5 > pikkused<-c(165, 172, 180) > pikkused+1 [1] 166 173 181 > pikkused/100 [1] 1.65 1.72 1.80 > library(tidyverse) > pikkused<-scan("http://www.tlu.ee/~jaagup/andmed/muu/pikkused.txt") Read 30 items > min(pikkused) [1] 141 > max(pikkused) [1] 170 > mean(pikkused) [1] 158.9 > median(pikkused) [1] 161 > range(pikkused) [1] 141 170 > summary(pikkused) Min. 1st Qu. Median Mean 3rd Qu. Max. 141.0 155.2 161.0 158.9 164.8 170.0 > range(pikkused)[[1]] [1] 141 > range(pikkused)[1] [1] 141 > summary(pikkused)[[1]] [1] 141 > summary(pikkused)[1] Min. 141 > hist(pikkused) > hist(rnorm(1000, 170, 10)) > hist(pikkused, breaks=3) > hist(pikkused, breaks=10) > hist(pikkused, breaks=c(155, 165)) Error in hist.default(pikkused, breaks = c(155, 165)) : some 'x' not counted; maybe 'breaks' do not span range of 'x' > hist(pikkused, breaks=c(155, 165, 190)) Error in hist.default(pikkused, breaks = c(155, 165, 190)) : some 'x' not counted; maybe 'breaks' do not span range of 'x' > hist(pikkused, breaks=c(130, 155, 165, 190)) > hist(pikkused, breaks=c(130, 145, 165, 190)) > hist(pikkused, breaks=c(130, 145, 175, 190)) > hist(pikkused) > hist(pikkused, main = "Pikkuste jaotus") > hist(pikkused, main = "Pikkuste jaotus", xlab="cm", ylab="kogus") > hist(pikkused, col="red") > pikkused[pikkused<160] [1] 141 159 148 143 156 145 151 156 155 158 143 152 156 > pikkused[pikkused<155] [1] 141 148 143 145 151 143 152 > sort(pikkused[pikkused<155]) [1] 141 143 143 145 148 151 152 > plot(sort(pikkused[pikkused<155])) > #pikkuste joonis > pikkused[1] [1] 170 > len(pikkused) Error in len(pikkused) : could not find function "len" > length(pikkused) [1] 30 > pikkused[length(pikkused)] [1] 162 > tail(pikkused) [1] 152 156 164 165 164 162 > tail(pikkused, n=1) [1] 162 > head(pikkused) [1] 170 160 160 165 163 165 > range(pikkused) [1] 141 170 > boxplot(pikkused) > pikkused<-c(pikkused, 52) > pikkused [1] 170 160 160 165 163 165 141 159 164 148 143 169 156 165 170 [16] 145 151 156 164 155 158 164 170 143 152 156 164 165 164 162 [31] 52 > boxplot(pikkused) > #lisage loetellu ka üle kahe meetrin pikkune korvpallur > #vaadake boxploti > boxplot(c(pikkused, 202)) > ounad<-read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad100.txt", header=TRUE) Error in read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad100.txt", : unused argument (header = TRUE) > ounad<-read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad100.txt") Parsed with column specification: cols( ounasort = col_character(), diameeter = col_double() ) > head(ounad) # A tibble: 6 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett 3.99 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 Warning messages: 1: In doTryCatch(return(expr), name, parentenv, handler) : display list redraw incomplete 2: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state 3: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state 4: In doTryCatch(return(expr), name, parentenv, handler) : display list redraw incomplete 5: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state 6: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state > library(tidyverse) > ounad<-read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad100.txt") Parsed with column specification: cols( ounasort = col_character(), diameeter = col_double() ) > head(ounad) # A tibble: 6 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett 3.99 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 Warning messages: 1: In doTryCatch(return(expr), name, parentenv, handler) : display list redraw incomplete 2: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state 3: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state > ounad$diameeter [1] 3.68 1.79 3.99 3.66 1.95 3.26 3.65 2.56 [9] 5.52 2.53 9.76 3.65 2.91 8.16 2.85 3.67 [17] 3.47 2.80 1.01 5.50 2.85 4.03 1.95 7.48 [25] 3.49 3.44 2.28 3.06 1.99 3.58 2.22 2.81 [33] 5.53 2.13 2.19 3.87 1.71 1.82 1.93 3.48 [41] 0.42 3.91 4.01 2.74 4.04 2.64 3.48 3.05 [49] 3.21 3.49 6.13 2.51 2.00 2.59 4.43 3.41 [57] 2.27 1.64 3.35 1.43 2.76 2.77 2.96 3.44 [65] 5.67 2.55 2.74 2.85 3.52 1.99 4.53 2.06 [73] 2.39 2.98 4.50 6.92 2.18 3.23 4.30 3.11 [81] 1.99 4.42 0.75 5.20 2.36 1.85 3.65 6.84 [89] 4.13 3.96 2.11 1.17 1.32 3.34 1.66 3.21 [97] 2.66 1.57 2.56 4.10 > range(ounad$diameeter) [1] 0.42 9.76 > summary(ounad$diameeter) Min. 1st Qu. Median Mean 3rd Qu. 0.420 2.212 3.015 3.253 3.728 Max. 9.760 > ounad$ounasort [1] "Liivi sibul" "Liivi sibul" [3] "Kuldrenett" "Liivi sibul" [5] "Liivi sibul" "Liivi sibul" [7] "Kuldrenett" "Liivi sibul" [9] "Kuldrenett" "Kuldrenett" [11] "Kuldrenett" "Kuldrenett" [13] "Liivi sibul" "Kuldrenett" [15] "Liivi sibul" "Liivi sibul" [17] "Liivi sibul" "Liivi sibul" [19] "Liivi sibul" "Kuldrenett" [21] "Liivi sibul" "Liivi sibul" [23] "Liivi sibul" "Kuldrenett" [25] "Liivi sibul" "Liivi sibul" [27] "Liivi sibul" "Liivi sibul" [29] "Liivi sibul" "Liivi sibul" [31] "Liivi sibul" "Liivi sibul" [33] "Kuldrenett" "Liivi sibul" [35] "Liivi sibul" "Liivi sibul" [37] "Kuldrenett" "Kuldrenett" [39] "Kuldrenett" "Liivi sibul" [41] "Kuldrenett" "Liivi sibul" [43] "Liivi sibul" "Liivi sibul" [45] "Liivi sibul" "Liivi sibul" [47] "Liivi sibul" "Liivi sibul" [49] "Liivi sibul" "Kuldrenett" [51] "Kuldrenett" "Liivi sibul" [53] "Liivi sibul" "Liivi sibul" [55] "Liivi sibul" "Liivi sibul" [57] "Liivi sibul" "Kuldrenett" [59] "Liivi sibul" "Liivi sibul" [61] "Liivi sibul" "Liivi sibul" [63] "Liivi sibul" "Liivi sibul" [65] "Liivi sibul" "Liivi sibul" [67] "Liivi sibul" "Liivi sibul" [69] "Liivi sibul" "Liivi sibul" [71] "Liivi sibul" "Kuldrenett" [73] "Liivi sibul" "Liivi sibul" [75] "Liivi sibul" "Kuldrenett" [77] "Liivi sibul" "Liivi sibul" [79] "Liivi sibul" "Liivi sibul" [81] "Liivi sibul" "Liivi sibul" [83] "Kuldrenett" "Liivi sibul" [85] "Liivi sibul" "Liivi sibul" [87] "Kuldrenett" "Kuldrenett" [89] "Liivi sibul" "Liivi sibul" [91] "Liivi sibul" "Kuldrenett" [93] "Kuldrenett" "Liivi sibul" [95] "Liivi sibul" "Liivi sibul" [97] "Liivi sibul" "Liivi sibul" [99] "Liivi sibul" "Liivi sibul" > unique(ounad$ounasort) [1] "Liivi sibul" "Kuldrenett" > ounad$ounasort %>% unique() [1] "Liivi sibul" "Kuldrenett" > ounad %>% filter(ounasort=="Kuldrenett") # A tibble: 24 x 2 ounasort diameeter 1 Kuldrenett 3.99 2 Kuldrenett 3.65 3 Kuldrenett 5.52 4 Kuldrenett 2.53 5 Kuldrenett 9.76 6 Kuldrenett 3.65 7 Kuldrenett 8.16 8 Kuldrenett 5.5 9 Kuldrenett 7.48 10 Kuldrenett 5.53 # ... with 14 more rows > ounad %>% filter(ounasort=="Kuldrenett") -> kuldrenetid > min(kuldrenetid$diameeter) [1] 0.42 > filter(ounad, ounasort=="Kuldrenett") # A tibble: 24 x 2 ounasort diameeter 1 Kuldrenett 3.99 2 Kuldrenett 3.65 3 Kuldrenett 5.52 4 Kuldrenett 2.53 5 Kuldrenett 9.76 6 Kuldrenett 3.65 7 Kuldrenett 8.16 8 Kuldrenett 5.5 9 Kuldrenett 7.48 10 Kuldrenett 5.53 # ... with 14 more rows > filter(ounad, ounasort=="Kuldrenett")$diameeter [1] 3.99 3.65 5.52 2.53 9.76 3.65 8.16 5.50 7.48 [10] 5.53 1.71 1.82 1.93 0.42 3.49 6.13 1.64 2.06 [19] 6.92 0.75 3.65 6.84 1.17 1.32 > #Kuvage kuldrenettide keskmine diameeter > ounad %>% filter(ounasort=="Kuldrenett")$diameeter %>% mean() Error in .$filter(ounasort == "Kuldrenett") : 3 arguments passed to '$' which requires 2 > mean(filter(ounad, ounasort=="Kuldrenett")$diameeter) [1] 3.984167 > ounad %>% filter(ounasort=="Kuldrenett") %>% mean(.[["diameeter"]]) [1] NA Warning message: In mean.default(., .[["diameeter"]]) : argument is not numeric or logical: returning NA > ounad %>% filter(ounasort=="Kuldrenett") %>% collect %>% mean(.[["diameeter"]]) [1] NA Warning message: In mean.default(., .[["diameeter"]]) : argument is not numeric or logical: returning NA > mean(filter(ounad, ounasort=="Kuldrenett")$diameeter) [1] 3.984167 > ounad %>% group_by("ounasort") %>% summarise(kogus=n(), keskmine=mean(diameeter)) # A tibble: 1 x 3 `"ounasort"` kogus keskmine 1 ounasort 100 3.25 > ounad %>% group_by(ounasort) %>% summarise(kogus=n(), keskmine=mean(diameeter)) # A tibble: 2 x 3 ounasort kogus keskmine 1 Kuldrenett 24 3.98 2 Liivi sibul 76 3.02 Warning messages: 1: In doTryCatch(return(expr), name, parentenv, handler) : display list redraw incomplete 2: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state 3: In doTryCatch(return(expr), name, parentenv, handler) : invalid graphics state > #Kuvage tabelisse juurde ka standarhälve (sd) > ounad %>% group_by(ounasort) %>% summarise(kogus=n(), keskmine=mean(diameeter)) # A tibble: 2 x 3 ounasort kogus keskmine 1 Kuldrenett 24 3.98 2 Liivi sibul 76 3.02 > ounad %>% group_by(ounasort) %>% summarise(kogus=n(), + keskmine=mean(diameeter), standardhalve=sd(diameeter)) # A tibble: 2 x 4 ounasort kogus keskmine standardhalve 1 Kuldrenett 24 3.98 2.60 2 Liivi sibul 76 3.02 0.899 > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(dimeeter), suhe=(suurim-vahim)/mean(diameeter)) Error in summarise_impl(.data, dots) : Evaluation error: object 'dimeeter' not found. > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter), suhe=(suurim-vahim)/mean(diameeter)) # A tibble: 2 x 4 ounasort suurim vahim suhe 1 Kuldrenett 9.76 0.42 2.34 2 Liivi sibul 5.67 1.01 1.54 > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter), suhe=(suurim-vahim)/mean(diameeter)) -> abi > min(abi$vahim) [1] 0.42 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) # A tibble: 2 x 2 ounasort keskmine 1 Kuldrenett 3.98 2 Liivi sibul 3.02 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter))$keskmine Error in .$summarise(keskmine = mean(diameeter)) : 3 arguments passed to '$' which requires 2 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter))[[2]] Error in mean(diameeter) : object 'diameeter' not found > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) # A tibble: 2 x 2 ounasort keskmine 1 Kuldrenett 3.98 2 Liivi sibul 3.02 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) %>% . Error in .(.) : could not find function "." > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) %>% min(.$diameeter) Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables In addition: Warning message: Unknown or uninitialised column: 'diameeter'. > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) %>% min(.$keskmine) Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)) -> abi > min(abi$keskmine) [1] 3.021579 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter))) # A tibble: 2 x 2 ounasort keskmine 1 Kuldrenett 3.98 2 Liivi sibul 3.02 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)))$keskmine [1] 3.984167 3.021579 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter)))$keskmine %>% min() [1] 3.021579 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter))) # A tibble: 2 x 3 ounasort keskmine suurim 1 Kuldrenett 3.98 9.76 2 Liivi sibul 3.02 5.67 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) # A tibble: 2 x 3 ounasort keskmine suurim 1 Kuldrenett 3.98 9.76 2 Liivi sibul 3.02 5.67 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) # A tibble: 2 x 3 ounasort keskmine suurim 1 Liivi sibul 3.02 5.67 2 Kuldrenett 3.98 9.76 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% head(1) # A tibble: 1 x 3 ounasort keskmine suurim 1 Liivi sibul 3.02 5.67 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% head(1)$suurim Error in .$head(1) : 3 arguments passed to '$' which requires 2 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% (head(1))$suurim Error in .$(head(1)) : 3 arguments passed to '$' which requires 2 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% (head(1))$suurim Error in .$(head(1)) : 3 arguments passed to '$' which requires 2 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% head(1)[[3]] [1] 5.67 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine) %>% head(1)[["suurim"]] [1] 5.67 > ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine)[["suurim"]] Error in arrange(keskmine) : object 'keskmine' not found > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine))[["suurim"]] [1] 5.67 9.76 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine))[["suurim"]][[1]] [1] 5.67 > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine))$[1] Error: unexpected '[' in "(ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine))$[" > (ounad %>% group_by(ounasort) %>% summarise(keskmine=mean(diameeter), suurim=max(diameeter)) %>% arrange(keskmine))$suurim[1] [1] 5.67 > ounad %>% select(ounasort) # A tibble: 100 x 1 ounasort 1 Liivi sibul 2 Liivi sibul 3 Kuldrenett 4 Liivi sibul 5 Liivi sibul 6 Liivi sibul 7 Kuldrenett 8 Liivi sibul 9 Kuldrenett 10 Kuldrenett # ... with 90 more rows > ounad$ounasort [1] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [6] "Liivi sibul" "Kuldrenett" "Liivi sibul" "Kuldrenett" "Kuldrenett" [11] "Kuldrenett" "Kuldrenett" "Liivi sibul" "Kuldrenett" "Liivi sibul" [16] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" [21] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" [26] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [31] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [36] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Kuldrenett" "Liivi sibul" [41] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [46] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" [51] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [56] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [61] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [66] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [71] "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" [76] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [81] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [86] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Liivi sibul" "Liivi sibul" [91] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Liivi sibul" "Liivi sibul" [96] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" > ounad[["ounasort"]] [1] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [6] "Liivi sibul" "Kuldrenett" "Liivi sibul" "Kuldrenett" "Kuldrenett" [11] "Kuldrenett" "Kuldrenett" "Liivi sibul" "Kuldrenett" "Liivi sibul" [16] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" [21] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" [26] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [31] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [36] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Kuldrenett" "Liivi sibul" [41] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [46] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Kuldrenett" [51] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [56] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [61] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [66] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [71] "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" [76] "Kuldrenett" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" [81] "Liivi sibul" "Liivi sibul" "Kuldrenett" "Liivi sibul" "Liivi sibul" [86] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Liivi sibul" "Liivi sibul" [91] "Liivi sibul" "Kuldrenett" "Kuldrenett" "Liivi sibul" "Liivi sibul" [96] "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" "Liivi sibul" > ounad[["ounasort"]][22] [1] "Liivi sibul" > ounad %>% mutate(mmdiam=diameeter*10) # A tibble: 100 x 3 ounasort diameeter mmdiam 1 Liivi sibul 3.68 36.8 2 Liivi sibul 1.79 17.9 3 Kuldrenett 3.99 39.9 4 Liivi sibul 3.66 36.6 5 Liivi sibul 1.95 19.5 6 Liivi sibul 3.26 32.6 7 Kuldrenett 3.65 36.5 8 Liivi sibul 2.56 25.6 9 Kuldrenett 5.52 55.2 10 Kuldrenett 2.53 25.3 # ... with 90 more rows > ounad %>% filter(diameeter>2 & diameeter<3) # A tibble: 30 x 2 ounasort diameeter 1 Liivi sibul 2.56 2 Kuldrenett 2.53 3 Liivi sibul 2.91 4 Liivi sibul 2.85 5 Liivi sibul 2.8 6 Liivi sibul 2.85 7 Liivi sibul 2.28 8 Liivi sibul 2.22 9 Liivi sibul 2.81 10 Liivi sibul 2.13 # ... with 20 more rows > ounad %>% filter(diameeter>2 , diameeter<3) # A tibble: 30 x 2 ounasort diameeter 1 Liivi sibul 2.56 2 Kuldrenett 2.53 3 Liivi sibul 2.91 4 Liivi sibul 2.85 5 Liivi sibul 2.8 6 Liivi sibul 2.85 7 Liivi sibul 2.28 8 Liivi sibul 2.22 9 Liivi sibul 2.81 10 Liivi sibul 2.13 # ... with 20 more rows > ounad %>% filter(diameeter<2 | diameeter>6) # A tibble: 25 x 2 ounasort diameeter 1 Liivi sibul 1.79 2 Liivi sibul 1.95 3 Kuldrenett 9.76 4 Kuldrenett 8.16 5 Liivi sibul 1.01 6 Liivi sibul 1.95 7 Kuldrenett 7.48 8 Liivi sibul 1.99 9 Kuldrenett 1.71 10 Kuldrenett 1.82 # ... with 15 more rows > ounad %>% filter(is.na(diameeter)) # A tibble: 0 x 2 # ... with 2 variables: ounasort , diameeter > ounad[[2]] [1] 3.68 1.79 3.99 3.66 1.95 3.26 3.65 2.56 5.52 2.53 9.76 3.65 2.91 8.16 2.85 [16] 3.67 3.47 2.80 1.01 5.50 2.85 4.03 1.95 7.48 3.49 3.44 2.28 3.06 1.99 3.58 [31] 2.22 2.81 5.53 2.13 2.19 3.87 1.71 1.82 1.93 3.48 0.42 3.91 4.01 2.74 4.04 [46] 2.64 3.48 3.05 3.21 3.49 6.13 2.51 2.00 2.59 4.43 3.41 2.27 1.64 3.35 1.43 [61] 2.76 2.77 2.96 3.44 5.67 2.55 2.74 2.85 3.52 1.99 4.53 2.06 2.39 2.98 4.50 [76] 6.92 2.18 3.23 4.30 3.11 1.99 4.42 0.75 5.20 2.36 1.85 3.65 6.84 4.13 3.96 [91] 2.11 1.17 1.32 3.34 1.66 3.21 2.66 1.57 2.56 4.10 > ounad[[2]][[3]] [1] 3.99 > ounad[[2]][[3]]<-NA > ounad # A tibble: 100 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% filter(is.na(diameeter)) # A tibble: 1 x 2 ounasort diameeter 1 Kuldrenett NA > ounad[[2]][[3]]<-4.12 > ounad # A tibble: 100 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett 4.12 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad[[2]][[3]]<-NA > ounad %>% filter(!is.na(diameeter)) # A tibble: 99 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Liivi sibul 3.66 4 Liivi sibul 1.95 5 Liivi sibul 3.26 6 Kuldrenett 3.65 7 Liivi sibul 2.56 8 Kuldrenett 5.52 9 Kuldrenett 2.53 10 Kuldrenett 9.76 # ... with 89 more rows > ounad %>% filter(!is.na()) Error in filter_impl(.data, quo) : Evaluation error: 0 arguments passed to 'is.na' which requires 1. > complete.cases(ounad) [1] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [73] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [85] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [97] TRUE TRUE TRUE TRUE > ounad[complete.cases(ounad)] Error: Length of logical index vector must be 1 or 2 (the number of columns), not 100 > na.omit(ounad) # A tibble: 99 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Liivi sibul 3.66 4 Liivi sibul 1.95 5 Liivi sibul 3.26 6 Kuldrenett 3.65 7 Liivi sibul 2.56 8 Kuldrenett 5.52 9 Kuldrenett 2.53 10 Kuldrenett 9.76 # ... with 89 more rows > ounad %>% complete.cases(.) [1] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [73] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [85] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [97] TRUE TRUE TRUE TRUE > ounad %>% filter(complete.cases(.)) # A tibble: 99 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Liivi sibul 3.66 4 Liivi sibul 1.95 5 Liivi sibul 3.26 6 Kuldrenett 3.65 7 Liivi sibul 2.56 8 Kuldrenett 5.52 9 Kuldrenett 2.53 10 Kuldrenett 9.76 # ... with 89 more rows > filter(ounad, complete.cases(ounad)) # A tibble: 99 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Liivi sibul 3.66 4 Liivi sibul 1.95 5 Liivi sibul 3.26 6 Kuldrenett 3.65 7 Liivi sibul 2.56 8 Kuldrenett 5.52 9 Kuldrenett 2.53 10 Kuldrenett 9.76 # ... with 89 more rows > ounad %>% arrange(diameeter) # A tibble: 100 x 2 ounasort diameeter 1 Kuldrenett 0.42 2 Kuldrenett 0.75 3 Liivi sibul 1.01 4 Kuldrenett 1.17 5 Kuldrenett 1.32 6 Liivi sibul 1.43 7 Liivi sibul 1.57 8 Kuldrenett 1.64 9 Liivi sibul 1.66 10 Kuldrenett 1.71 # ... with 90 more rows > ounad %>% arrange(desc(diameeter)) # A tibble: 100 x 2 ounasort diameeter 1 Kuldrenett 9.76 2 Kuldrenett 8.16 3 Kuldrenett 7.48 4 Kuldrenett 6.92 5 Kuldrenett 6.84 6 Kuldrenett 6.13 7 Liivi sibul 5.67 8 Kuldrenett 5.53 9 Kuldrenett 5.52 10 Kuldrenett 5.5 # ... with 90 more rows > #Kuvage kuldrenetid kahanevas diameetri järjekorras > ounad %>% filter(ounasort=="Kuldrenett") %>% arrange(desc(diameeter)) # A tibble: 24 x 2 ounasort diameeter 1 Kuldrenett 9.76 2 Kuldrenett 8.16 3 Kuldrenett 7.48 4 Kuldrenett 6.92 5 Kuldrenett 6.84 6 Kuldrenett 6.13 7 Kuldrenett 5.53 8 Kuldrenett 5.52 9 Kuldrenett 5.5 10 Kuldrenett 3.65 # ... with 14 more rows > ounad %>% filter(ounasort=="Kuldrenett") %>% arrange(diameeter) # A tibble: 24 x 2 ounasort diameeter 1 Kuldrenett 0.42 2 Kuldrenett 0.75 3 Kuldrenett 1.17 4 Kuldrenett 1.32 5 Kuldrenett 1.64 6 Kuldrenett 1.71 7 Kuldrenett 1.82 8 Kuldrenett 1.93 9 Kuldrenett 2.06 10 Kuldrenett 2.53 # ... with 14 more rows > ounad %>% select(-diameeter) # A tibble: 100 x 1 ounasort 1 Liivi sibul 2 Liivi sibul 3 Kuldrenett 4 Liivi sibul 5 Liivi sibul 6 Liivi sibul 7 Kuldrenett 8 Liivi sibul 9 Kuldrenett 10 Kuldrenett # ... with 90 more rows > ounad %>% select(-(diameeter, ounasort)) Error: unexpected ',' in "ounad %>% select(-(diameeter," > ounad %>% select(-c(diameeter, ounasort)) # A tibble: 100 x 0 > ounad %>% select(contains("o")) # A tibble: 100 x 1 ounasort 1 Liivi sibul 2 Liivi sibul 3 Kuldrenett 4 Liivi sibul 5 Liivi sibul 6 Liivi sibul 7 Kuldrenett 8 Liivi sibul 9 Kuldrenett 10 Kuldrenett # ... with 90 more rows > ounad %>% select(contains("a")) # A tibble: 100 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% select(contains("x")) # A tibble: 100 x 0 > ounad %>% rename(labimoot=diameeter) # A tibble: 100 x 2 ounasort labimoot 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% rename(labimoot=diameeter*10) Error in .f(.x[[i]], ...) : object 'diameeter' not found > ounad %>% rename(labimoot=ounad$diameeter*10) Error: Column positions must be round numbers > ounad %>% rename(labimoot=diameeter) # A tibble: 100 x 2 ounasort labimoot 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% select(diameeter, everything()) # A tibble: 100 x 2 diameeter ounasort 1 3.68 Liivi sibul 2 1.79 Liivi sibul 3 NA Kuldrenett 4 3.66 Liivi sibul 5 1.95 Liivi sibul 6 3.26 Liivi sibul 7 3.65 Kuldrenett 8 2.56 Liivi sibul 9 5.52 Kuldrenett 10 2.53 Kuldrenett # ... with 90 more rows > ounad %>% mutate(mm=diameeter*10) # A tibble: 100 x 3 ounasort diameeter mm 1 Liivi sibul 3.68 36.8 2 Liivi sibul 1.79 17.9 3 Kuldrenett NA NA 4 Liivi sibul 3.66 36.6 5 Liivi sibul 1.95 19.5 6 Liivi sibul 3.26 32.6 7 Kuldrenett 3.65 36.5 8 Liivi sibul 2.56 25.6 9 Kuldrenett 5.52 55.2 10 Kuldrenett 2.53 25.3 # ... with 90 more rows > ounad %>% transmute(mm=diameeter*10) # A tibble: 100 x 1 mm 1 36.8 2 17.9 3 NA 4 36.6 5 19.5 6 32.6 7 36.5 8 25.6 9 55.2 10 25.3 # ... with 90 more rows > ounad %>% transmute(mm=diameeter*10, osort=ounasort) # A tibble: 100 x 2 mm osort 1 36.8 Liivi sibul 2 17.9 Liivi sibul 3 NA Kuldrenett 4 36.6 Liivi sibul 5 19.5 Liivi sibul 6 32.6 Liivi sibul 7 36.5 Kuldrenett 8 25.6 Liivi sibul 9 55.2 Kuldrenett 10 25.3 Kuldrenett # ... with 90 more rows > ounad %>% transmute(mm=diameeter*10, ounasort=ounasort) # A tibble: 100 x 2 mm ounasort 1 36.8 Liivi sibul 2 17.9 Liivi sibul 3 NA Kuldrenett 4 36.6 Liivi sibul 5 19.5 Liivi sibul 6 32.6 Liivi sibul 7 36.5 Kuldrenett 8 25.6 Liivi sibul 9 55.2 Kuldrenett 10 25.3 Kuldrenett # ... with 90 more rows > ounad %>% transmute(cm=int(diameeter), mm=(diameeter-cm)*10) Error in mutate_impl(.data, dots) : Evaluation error: could not find function "int". > ounad %>% transmute(cm=floor(diameeter), mm=(diameeter-cm)*10) # A tibble: 100 x 2 cm mm 1 3 6.8 2 1 7.9 3 NA NA 4 3 6.6 5 1 9.5 6 3 2.60 7 3 6.50 8 2 5.6 9 5 5.20 10 2 5.30 # ... with 90 more rows > ounad # A tibble: 100 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% transmute(cm=floor(diameeter), mm=(diameeter-cm)*10) # A tibble: 100 x 2 cm mm 1 3 6.8 2 1 7.9 3 NA NA 4 3 6.6 5 1 9.5 6 3 2.60 7 3 6.50 8 2 5.6 9 5 5.20 10 2 5.30 # ... with 90 more rows > ounad # A tibble: 100 x 2 ounasort diameeter 1 Liivi sibul 3.68 2 Liivi sibul 1.79 3 Kuldrenett NA 4 Liivi sibul 3.66 5 Liivi sibul 1.95 6 Liivi sibul 3.26 7 Kuldrenett 3.65 8 Liivi sibul 2.56 9 Kuldrenett 5.52 10 Kuldrenett 2.53 # ... with 90 more rows > ounad %>% ggplot(aes(diameeter)) + geom_histogram() `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. Warning message: Removed 1 rows containing non-finite values (stat_bin). > ounad %>% ggplot(aes(diameeter)) + geom_histogram(bins = 6) Warning message: Removed 1 rows containing non-finite values (stat_bin). > ounad %>% na.omit() %>% ggplot(aes(diameeter)) + geom_histogram(bins = 6) > ounad<-read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad3_100.txt") Parsed with column specification: cols( ounasort = col_character(), diameeter = col_double() ) > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) # A tibble: 3 x 3 ounasort suurim vahim 1 Antoonovka 10.6 2.26 2 Kuldrenett 8.75 0.36 3 Liivi sibul 5.84 1.07 > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim, text=ounasort)) + geom_text() Error: geom_text requires the following missing aesthetics: label > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim, label=ounasort)) + geom_text() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim)) + geom_point() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim)) + geom_point() + geom_text(aes(y=vahim-0.1, label=ounasort)) > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim)) + geom_point() + geom_text(aes(y=vahim-0.1, label=ounasort)) + xlim(4, 12) > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim, y=vahim)) + geom_col() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=suurim)) + geom_col() Error in pmin(y, 0) : object 'y' not found > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(y=suurim)) + geom_col() Error in eval(substitute(list(...)), `_data`, parent.frame()) : object 'x' not found In addition: Warning messages: 1: In min(x, na.rm = na.rm) : no non-missing arguments to min; returning Inf 2: In max(x, na.rm = na.rm) : no non-missing arguments to max; returning -Inf 3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=1:3, y=suurim)) + geom_col() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=1:3, y=suurim, label=ounasort)) + geom_col() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=1:3, y=suurim)) + geom_col() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=factor(ounasort), y=suurim)) + geom_col() > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=factor(ounasort), y=suurim)) + geom_col() + xlab("Sordinimed") + ylab("suurim cm")+title("Õunte suurimad suurused sordit") > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=factor(ounasort), y=suurim)) + geom_col() + xlab("Sordinimed") + ylab("suurim cm")+main("Õunte suurimad suurused sorditi") Error in main("Õunte suurimad suurused sorditi") : could not find function "main" > ounad %>% group_by(ounasort) %>% summarise(suurim=max(diameeter), vahim=min(diameeter)) %>% ggplot(aes(x=factor(ounasort), y=suurim)) + geom_col() + xlab("Sordinimed") + ylab("suurim cm")+ggtitle("Õunte suurimad suurused sorditi") > ounad=read_csv("http://www.tlu.ee/~jaagup/andmed/muu/ounad/liivi_antoonovka_aug_sept_1000.txt") Parsed with column specification: cols( ounasort = col_character(), august = col_double(), september = col_double() ) > ounad %>% ggplot(aes(august, september))+geom_point() > ounad %>% ggplot(aes(august, september, color=ounasort))+geom_point() > ?geom_text > ounad %>% group_by(ounasort) %>% summarise(augkesk=mean(august)) # A tibble: 2 x 2 ounasort augkesk 1 Antoonovka 4.99 2 Liivi sibul 3.02 > ounad %>% group_by(ounasort) %>% summarise(augkesk=mean(august)) %>% ggplot(aes(ounasort, augkesk)) + geom_col()