> 1+2 [1] 3 > 2**5 [1] 32 > a=3 > a [1] 3 > a <- 3 > a [1] 3 > 3+7 -> b > b [1] 10 > b=b+1 > b [1] 11 > sqrt(25) [1] 5 > install.packages("languageR") Installing package into ‘C:/Users/zeus/Documents/R/win-library/3.3’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/languageR_1.4.1.zip' Content type 'application/zip' length 2389110 bytes (2.3 MB) downloaded 2.3 MB package ‘languageR’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\zeus\AppData\Local\Temp\Rtmpq8Vz43\downloaded_packages > library(languageR) > head(verbs) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 1 NP feed animate inanimate 2.639057 2 NP give animate inanimate 1.098612 3 NP give animate inanimate 2.564949 4 NP give animate inanimate 1.609438 5 NP offer animate inanimate 1.098612 6 NP give animate inanimate 1.386294 > nrow(verbs) [1] 903 > write.table(verbs, "d:/jaagup/xmldigi/algus/sonad1.csv") > write.table(verbs, "d:/jaagup/xmldigi/algus/sonad1.csv", sep=",", row.names = FALSE) > write.table(verbs, "d:/jaagup/xmldigi/algus/sonad1.csv", sep=";", row.names = FALSE) > help(verbs) > example(verbs) verbs> data(verbs) verbs> head(verbs) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 1 NP feed animate inanimate 2.639057 2 NP give animate inanimate 1.098612 3 NP give animate inanimate 2.564949 4 NP give animate inanimate 1.609438 5 NP offer animate inanimate 1.098612 6 NP give animate inanimate 1.386294 verbs> xtabs( ~ RealizationOfRec + AnimacyOfRec, data = verbs) AnimacyOfRec RealizationOfRec animate inanimate NP 521 34 PP 301 47 verbs> barplot(xtabs( ~ RealizationOfRec + AnimacyOfRec, data = verbs),beside=TRUE) Hit to see next plot: > > verbs[2, 3] [1] animate Levels: animate inanimate > verbs[2, ] RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 2 NP give animate inanimate 1.098612 > head(verbs$Verb) [1] feed give give give offer give 65 Levels: accord allocate allow assess assure award bequeath bet bring ... wish > verbs[2, "Verb"] [1] give 65 Levels: accord allocate allow assess assure award bequeath bet bring ... wish > loetelu=c(13, 85, 243) > verbs[loetelu, ] RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 13 NP pay animate inanimate 1.6094379 85 NP offer animate inanimate 1.3862944 243 NP will animate inanimate 0.6931472 > 25:30 [1] 25 26 27 28 29 30 > verbs[25:30,] RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 25 NP give animate inanimate 2.3025851 26 NP give inanimate inanimate 3.1354942 27 NP give inanimate inanimate 0.6931472 28 NP give animate inanimate 2.5649494 29 NP give animate inanimate 2.8903718 30 NP send animate inanimate 0.0000000 > verbs[25:30, c("Verb", "AnimacyOfRec")] Verb AnimacyOfRec 25 give animate 26 give inanimate 27 give inanimate 28 give animate 29 give animate 30 send animate > verbs[25:30, 3:5] AnimacyOfRec AnimacyOfTheme LengthOfTheme 25 animate inanimate 2.3025851 26 inanimate inanimate 3.1354942 27 inanimate inanimate 0.6931472 28 animate inanimate 2.5649494 29 animate inanimate 2.8903718 30 animate inanimate 0.0000000 > head(verbs[verbs$AnimacyOfRec, ]) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 1 NP feed animate inanimate 2.639057 1.1 NP feed animate inanimate 2.639057 1.2 NP feed animate inanimate 2.639057 1.3 NP feed animate inanimate 2.639057 1.4 NP feed animate inanimate 2.639057 1.5 NP feed animate inanimate 2.639057 > head(verbs[verbs$AnimacyOfRec=="animate", ]) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 1 NP feed animate inanimate 2.639057 2 NP give animate inanimate 1.098612 3 NP give animate inanimate 2.564949 4 NP give animate inanimate 1.609438 5 NP offer animate inanimate 1.098612 6 NP give animate inanimate 1.386294 > head(verbs[verbs$AnimacyOfRec=="inanimate", ]) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 12 NP give inanimate inanimate 1.0986123 26 NP give inanimate inanimate 3.1354942 27 NP give inanimate inanimate 0.6931472 67 NP give inanimate inanimate 1.6094379 71 NP pay inanimate inanimate 0.6931472 74 NP give inanimate inanimate 1.0986123 > write.table(verbs[verbs$AnimacyOfRec=="inanimate", ], "d:/jaagup/xmldigi/algus/sonad2.csv", sep=";", row.names=FALSE) > arvud=c(6, 8, 5) > sort(arvud) [1] 5 6 8 > order(arvud) [1] 3 1 2 > arvid Error: object 'arvid' not found > arvud [1] 6 8 5 > order(arvud) [1] 3 1 2 > arvud[order(arvud)] [1] 5 6 8 > head(order(verbs$LengthOfTheme)) [1] 8 30 102 103 157 158 > verbs[head(order(verbs$LengthOfTheme)),] RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 8 NP bring animate inanimate 0 30 NP send animate inanimate 0 102 NP bet animate inanimate 0 103 NP tell animate inanimate 0 157 NP tell animate inanimate 0 158 NP give inanimate inanimate 0 > #Leidke tähestiku järgi esimeste verbidega read > verbs[head(order(verbs$Verb)),] RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 240 NP accord animate inanimate 1.6094379 667 PP allocate inanimate inanimate 0.6931472 882 PP allocate inanimate inanimate 1.9459101 883 PP allocate inanimate inanimate 0.6931472 83 NP allow animate inanimate 1.7917595 133 NP allow animate inanimate 2.8332133 > head(sort(verbs$Verb), 20) [1] accord allocate allocate allocate allow allow allow allow [9] allow allow assess assure assure award award award [17] award award award award 65 Levels: accord allocate allow assess assure award bequeath bet bring ... wish > nchar("tere") [1] 4 > arvud [1] 6 8 5 > arvud+1 [1] 7 9 6 > arvud=c(6, 8, 5) > arvud*2 [1] 12 16 10 > sonad=c("kui", "Arno", "isaga") > nchar(sonad) [1] 3 4 5 > class(verbs$Verb) [1] "factor" > class(sonad) [1] "character" > head(verbs$Verb) [1] feed give give give offer give 65 Levels: accord allocate allow assess assure award bequeath bet bring ... wish > nchar(head(verbs$Verb)) Error in nchar(head(verbs$Verb)) : 'nchar()' requires a character vector > head(as.character(verbs$Verb)) [1] "feed" "give" "give" "give" "offer" "give" > nchar(head(as.character(verbs$Verb))) [1] 4 4 4 4 5 4 > verbs$pikkus=nchar(as.character(verbs$verb)) Error in `$<-.data.frame`(`*tmp*`, "pikkus", value = integer(0)) : replacement has 0 rows, data has 903 > verbs$pikkus=nchar(as.character(verbs$Verb)) > head(verbs) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme pikkus 1 NP feed animate inanimate 2.639057 4 2 NP give animate inanimate 1.098612 4 3 NP give animate inanimate 2.564949 4 4 NP give animate inanimate 1.609438 4 5 NP offer animate inanimate 1.098612 5 6 NP give animate inanimate 1.386294 4 > verbs$pikkus=NULL > head(verbs) RealizationOfRec Verb AnimacyOfRec AnimacyOfTheme LengthOfTheme 1 NP feed animate inanimate 2.639057 2 NP give animate inanimate 1.098612 3 NP give animate inanimate 2.564949 4 NP give animate inanimate 1.609438 5 NP offer animate inanimate 1.098612 6 NP give animate inanimate 1.386294 > eesnimed=c("Juku", "Kati", "Mati", "Kati", "Juku") > xtabs(eesnimed) Error in eval(expr, envir, enclos) : object 'Juku' not found > table(eesnimed) eesnimed Juku Kati Mati 2 2 1 > levels(verbs$RealizationOfRec) [1] "NP" "PP" > xtabs(~ RealizationOfRec, verbs) RealizationOfRec NP PP 555 348 > xtabs(~ RealizationOfRec+AnimacyOfRec, verbs) AnimacyOfRec RealizationOfRec animate inanimate NP 521 34 PP 301 47 > xtabs(~ RealizationOfRec+AnimacyOfRec, verbs)/nrow(verbs) AnimacyOfRec RealizationOfRec animate inanimate NP 0.57696567 0.03765227 PP 0.33333333 0.05204873 > xtabs(~ RealizationOfRec+AnimacyOfRec, verbs)*100/nrow(verbs) AnimacyOfRec RealizationOfRec animate inanimate NP 57.696567 3.765227 PP 33.333333 5.204873 > round(xtabs(~ RealizationOfRec+AnimacyOfRec, verbs)*100/nrow(verbs),1) AnimacyOfRec RealizationOfRec animate inanimate NP 57.7 3.8 PP 33.3 5.2 > 1:5 [1] 1 2 3 4 5 > sum(1:5) [1] 15 > head(verbs[verbs$AnimacyOfRec=="animate", "LengthOfTheme"]) [1] 2.639057 1.098612 2.564949 1.609438 1.098612 1.386294 > mean(verbs[verbs$AnimacyOfRec=="animate", "LengthOfTheme"]) [1] 1.540278 > mean(verbs[verbs$AnimacyOfRec!="animate", "LengthOfTheme"]) [1] 1.07113 > tapply(verbs$LengthOfTheme, verbs$AnimacyOfRec, mean) animate inanimate 1.540278 1.071130 > tapply(verbs$LengthOfTheme, verbs$AnimacyOfRec, sum) animate inanimate 1266.10862 86.76151 > objects() [1] "a" "arvud" "b" "eesnimed" "loetelu" "mtcars" "sonad" [8] "t" "v" "verbs" > a [1] 3 > rm(a) > objects() [1] "arvud" "b" "eesnimed" "loetelu" "mtcars" "sonad" "t" [8] "v" "verbs" > head(spanishMeta) Author YearOfBirth TextName PubDate Nwords FullName 1 C 1916 X14458gll 1983 2972 Cela 2 C 1916 X14459gll 1951 3040 Cela 3 C 1916 X14460gll 1956 3066 Cela 4 C 1916 X14461gll 1948 3044 Cela 5 C 1916 X14462gll 1942 3053 Cela 6 M 1943 X14463gll 1986 3013 Mendoza > colnames(spanishMeta) [1] "Author" "YearOfBirth" "TextName" "PubDate" "Nwords" [6] "FullName" > nrow(spanishMeta) [1] 15 > length(spanishMeta) [1] 6 > length(spanishMeta$Author) [1] 15 > tapply(spanishMeta$FullName, spanishMeta$FullName, length) Cela Mendoza VargasLLosa 5 5 5 > tapply(spanishMeta$PubDate, spanishMeta$FullName, mean) Cela Mendoza VargasLLosa 1956.0 1990.2 1974.6 > round(tapply(spanishMeta$PubDate, spanishMeta$FullName, mean)) Cela Mendoza VargasLLosa 1956 1990 1975 > tapply(spanishMeta$PubDate, spanishMeta$FullName, c(mean, length)) Error in match.fun(FUN) : 'c(mean, length)' is not a function, character or symbol > spanishMeta[order(spanishMeta$YearOfBirth), ] Author YearOfBirth TextName PubDate Nwords FullName 1 C 1916 X14458gll 1983 2972 Cela 2 C 1916 X14459gll 1951 3040 Cela 3 C 1916 X14460gll 1956 3066 Cela 4 C 1916 X14461gll 1948 3044 Cela 5 C 1916 X14462gll 1942 3053 Cela 11 V 1936 X14472gll 1965 3037 VargasLLosa 12 V 1936 X14473gll 1963 3067 VargasLLosa 13 V 1936 X14474gll 1977 3020 VargasLLosa 14 V 1936 X14475gll 1987 3016 VargasLLosa 15 V 1936 X14476gll 1981 3054 VargasLLosa 6 M 1943 X14463gll 1986 3013 Mendoza 7 M 1943 X14464gll 1992 3049 Mendoza 8 M 1943 X14465gll 1989 3042 Mendoza 9 M 1943 X14466gll 1982 3039 Mendoza 10 M 1943 X14467gll 2002 3045 Mendoza > spanishMeta[order(spanishMeta$YearOfBirth, spanishMeta$Nwords), ] Author YearOfBirth TextName PubDate Nwords FullName 1 C 1916 X14458gll 1983 2972 Cela 2 C 1916 X14459gll 1951 3040 Cela 4 C 1916 X14461gll 1948 3044 Cela 5 C 1916 X14462gll 1942 3053 Cela 3 C 1916 X14460gll 1956 3066 Cela 14 V 1936 X14475gll 1987 3016 VargasLLosa 13 V 1936 X14474gll 1977 3020 VargasLLosa 11 V 1936 X14472gll 1965 3037 VargasLLosa 15 V 1936 X14476gll 1981 3054 VargasLLosa 12 V 1936 X14473gll 1963 3067 VargasLLosa 6 M 1943 X14463gll 1986 3013 Mendoza 9 M 1943 X14466gll 1982 3039 Mendoza 8 M 1943 X14465gll 1989 3042 Mendoza 10 M 1943 X14467gll 2002 3045 Mendoza 7 M 1943 X14464gll 1992 3049 Mendoza > spanishMeta$PubDate [1] 1983 1951 1956 1948 1942 1986 1992 1989 1982 2002 1965 1963 1977 1987 1981 > sort(spanishMeta$PubDate) [1] 1942 1948 1951 1956 1963 1965 1977 1981 1982 1983 1986 1987 1989 1992 2002 > help("sort") > sort(spanishMeta$PubDate, decreasing=TRUE) [1] 2002 1992 1989 1987 1986 1983 1982 1981 1977 1965 1963 1956 1951 1948 1942 > spanishMeta[spanishMeta$PubDate<1980, ] Author YearOfBirth TextName PubDate Nwords FullName 2 C 1916 X14459gll 1951 3040 Cela 3 C 1916 X14460gll 1956 3066 Cela 4 C 1916 X14461gll 1948 3044 Cela 5 C 1916 X14462gll 1942 3053 Cela 11 V 1936 X14472gll 1965 3037 VargasLLosa 12 V 1936 X14473gll 1963 3067 VargasLLosa 13 V 1936 X14474gll 1977 3020 VargasLLosa > isikud=read.table("http://minitorn.tlu.ee/~jaagup/kool/java/kursused/17/xmlrak/digi/algus/tuttavad.txt", sep=",", header=TRUE) 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 > isikud=read.table("http://minitorn.tlu.ee/~jaagup/kool/java/kursused/17/xmlrak/digi/algus/tuttavad.txt", sep=",", header=TRUE) > isikud eesnimi pikkus sugu synniaasta 1 Jaagup 180 M 1976 2 Pille 170 N 1935 3 Paula 122 N 2010 4 Toomas 142 M 2008 5 Viivi 167 N 1939 6 Andi 167 M 1976 7 Enrik 176 M 1979 8 Vaike 180 N 1976 > isikud[isikud$sugu="N", ] Error: unexpected '=' in "isikud[isikud$sugu=" > isikud[isikud$sugu=="N", ] eesnimi pikkus sugu synniaasta 2 Pille 170 N 1935 3 Paula 122 N 2010 5 Viivi 167 N 1939 8 Vaike 180 N 1976 > isikud[isikud$sugu=="N", "synniaasta"] [1] 1935 2010 1939 1976 > min(isikud[isikud$sugu=="N", "synniaasta"]) [1] 1935 > tapply(isikud$pikkus, isikud$sugu, mean) M N 166.25 159.75