R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-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. > source("cv1.R") Cviceni c. 1 Na dalsi ukol se dostanete klavesou c nebo ENTER. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> 1. Vyzkousejte rozdily ve vypisech mezi definicemi vektoru "v": v <- c(1,2,3) a (v <- c(1,2,3)) Called from: eval.with.vis(expr, envir, enclos) Browse[1]> v <- c(1, 2, 3) # bez vytisteni na obrazovku Browse[1]> (v <- c(1, 2, 3)) # s vytistenim na obrazovku [1] 1 2 3 Browse[1]> 2. Dvema zpusoby zobrazte napovedu k funkci matrix, pomoci funce args() zjistete jeji argumenty. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> # prikaz ### argumenty funkce function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) NULL Browse[1]> 3. Zjistete, ve kterem adresari se nachazite. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] "/home_stud/xkonecn3/vypsyst/cviceni_R" Browse[1]> 4. Vytvorte numericky vektor "x" s hodnotami 2, 4.7, 8, 3.1, 19, 7. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> x [1] 2.0 4.7 8.0 3.1 19.0 7.0 Browse[1]> 5. Vytvorte numericky vektor "y" s komplexnimi hodnotami 2, 5i, 3+i, 0.5+i. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> y [1] 2.0+0i 0.0+5i 3.0+1i 0.5+1i Browse[1]> 6. Vytvorte textovy vektor s nazvem "mesta" a slozkami "Praha", "Brno", "Ostrava", "Plzen", "Olomouc", "Karlovy Vary", "Liberec", "Ceske Budejovice", "Pardubice", "Most". Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> mesta [1] "Praha" "Brno" "Ostrava" "Plzen" [5] "Olomouc" "Karlovy Vary" "Liberec" "Ceske Budejovice" [9] "Pardubice" "Most" Browse[1]> 7. Vytvorte posloupnost "p" rozsahu 10 s pocatecni hodnotou 2 a krokem 2.5. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> p [1] 2.0 4.5 7.0 9.5 12.0 14.5 17.0 19.5 22.0 24.5 Browse[1]> 8. Vytvorte posloupnost "q" obsahujici 3, 2, ... -2, -3. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> q [1] 3 2 1 0 -1 -2 -3 Browse[1]> 9. Vytvorte posloupnost "r" peti za sebou jdoucich nul a peti za sebou jdoucich jednicek. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> r [1] 0 0 0 0 0 1 1 1 1 1 Browse[1]> 10. Vytvorte posloupnost "s" petkrat za sebou se opakujicich nul a jednicek. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> s [1] 0 1 0 1 0 1 0 1 0 1 Browse[1]> 11. Nahodne vygenerujte pet nazvu mest z vektoru "mesta". Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] "Praha" "Liberec" "Pardubice" "Brno" "Karlovy Vary" Browse[1]> 12. Zjistete delku vektoru "mesta". Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] 10 Browse[1]> 13. Pomoci funkce "sample" vygenerujte vektor "A", ktery bude obsahovat pet nazvu mest z vektoru "mesta":, nejvyssi vahu (1) priradte mestu Praha, vahy 0.5 priradte Brnu, Ostrave a Plzni, ostatnim mestum priradte vahu 0.1. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] "Praha" "Ostrava" "Brno" "Olomouc" "Karlovy Vary" Browse[1]> 14. Pomoci funkci "head" a "tail" priradte do jednoho vektoru "vyber" prvni ctyri a posledni dve mesta vektoru "mesta". Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> vyber [1] "Praha" "Brno" "Ostrava" "Plzen" "Pardubice" "Most" Browse[1]> 15. Vypiste mesta na sudych pozicich vektoru "mesta" a pridejte k nim misto vaseho bydliste. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] "Brno" "Plzen" "Karlovy Vary" "Ceske Budejovice" [5] "Most" "Prusanky" 16. Vytvorte faktor "fact" se slozkami 0, 1, 1, 0, 1, 0, 0, 0, 1. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> fact [1] 0 1 1 0 1 0 0 0 1 Levels: 0 1 Browse[1]> 17. Upravte faktor "fact" tak, aby se misto 0 vypisovalo "FALSE" a misto 1 "TRUE". Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz Browse[1]> fact [1] FALSE TRUE TRUE FALSE TRUE FALSE FALSE FALSE TRUE Levels: FALSE TRUE Browse[1]> 18. Vypiste seznam vsech nadefinovanych objektu. Zkuste nektery z nich smazat. Opet vypiste seznam vsech objektu. Called from: eval.with.vis(expr, envir, enclos) Browse[1]> # prikaz [1] "fact" "mesta" "p" "q" "r" "s" [7] "v" "vyber" "x" "y" Browse[1]> # prikaz ### smazeme napr. obekty "fact", "p", "r" Browse[1]> # prikaz ### vypis [1] "mesta" "q" "s" "v" "vyber" "x" [7] "y" Browse[1]> >