R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin10.8.0 (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. Natural language support but running in an English locale 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. During startup - Warning messages: 1: Setting LC_CTYPE failed, using "C" 2: Setting LC_COLLATE failed, using "C" 3: Setting LC_TIME failed, using "C" 4: Setting LC_MESSAGES failed, using "C" 5: Setting LC_PAPER failed, using "C" [R.app GUI 1.61 (6492) x86_64-apple-darwin10.8.0] WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work. Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system preferences accordingly. [History restored from /Users/paullaskowski/Desktop/data/.Rapp.history] > 5 + 5 [1] 10 > x =5 > x [1] 5 > x <- 5 > 6 -> x > x [1] 6 > x = c(3, 4, 5) > x [1] 3 4 5 > y = c(1,2,3) > x + y [1] 4 6 8 > x * y [1] 3 8 15 > z = c(1, 2) > x + z [1] 4 6 6 Warning message: In x + z : longer object length is not a multiple of shorter object length > names = c("paul", "anna", "pierce") > names [1] "paul" "anna" "pierce" > names[1] [1] "paul" > names[names != "paul"] [1] "anna" "pierce" > names = names[names != "paul"] > names [1] "anna" "pierce" > Names Error: object 'Names' not found > names != "anna" [1] FALSE TRUE > names = c(names, "lisa", "andy") > names [1] "anna" "pierce" "lisa" "andy" > 'anna' [1] "anna" > x [1] 3 4 5 > x = c(x, "text") > x [1] "3" "4" "5" "text" > y= c(, 7, 6, 6) Error in c(, 7, 6, 6) : argument 1 is empty > y= c(9, 7, 6, 6) > y [1] 9 7 6 6 > pr = data.frame(names, y) > pr names y 1 anna 9 2 pierce 7 3 lisa 6 4 andy 6 > pr = data.frame(chef = names, score = y) > pr chef score 1 anna 9 2 pierce 7 3 lisa 6 4 andy 6 > pr$chef [1] anna pierce lisa andy Levels: andy anna lisa pierce > pr$score [1] 9 7 6 6 > names(pr) [1] "chef" "score" > names(pr)[2] [1] "score" > names(pr)[2] = "score1" > names(pr) [1] "chef" "score1" > pr chef score1 1 anna 9 2 pierce 7 3 lisa 6 4 andy 6 > pr$score2 = c(2,3,2,4) > pr$spiciness =c(3,2,1,2) > pr chef score1 score2 spiciness 1 anna 9 2 3 2 pierce 7 3 2 3 lisa 6 2 1 4 andy 6 4 2 > attach(pr) > score2 [1] 2 3 2 4 > score2 = score2 + 10 > score2 [1] 12 13 12 14 > pr$score2 [1] 2 3 2 4 > pr$spiciness [1] 3 2 1 2 > mean(pr$score1) [1] 7 > scale(pr$score1) [,1] [1,] 1.4142136 [2,] 0.0000000 [3,] -0.7071068 [4,] -0.7071068 attr(,"scaled:center") [1] 7 attr(,"scaled:scale") [1] 1.414214 > scale(pr$score1) -> pr$score1 > scale(pr$score2) -> pr$score2 > pr chef score1 score2 spiciness 1 anna 1.4142136 -0.7833495 3 2 pierce 0.0000000 0.2611165 2 3 lisa -0.7071068 -0.7833495 1 4 andy -0.7071068 1.3055824 2 > pr$total_score= (pr$score1 + pr$score2) / 2 > pr chef score1 score2 spiciness total_score 1 anna 1.4142136 -0.7833495 3 0.3154321 2 pierce 0.0000000 0.2611165 2 0.1305582 3 lisa -0.7071068 -0.7833495 1 -0.7452281 4 andy -0.7071068 1.3055824 2 0.2992378 > pr$above_av = pr$total_score > mean(pr$total_score) > pr chef score1 score2 spiciness total_score above_av 1 anna 1.4142136 -0.7833495 3 0.3154321 TRUE 2 pierce 0.0000000 0.2611165 2 0.1305582 TRUE 3 lisa -0.7071068 -0.7833495 1 -0.7452281 FALSE 4 andy -0.7071068 1.3055824 2 0.2992378 TRUE > > pr$spiciness [1] 3 2 1 2 > pr$chef [1] anna pierce lisa andy Levels: andy anna lisa pierce > pr$spiciness = factor(spiciness, levels=c(1,2,3), labels=c("mild","spicy", "extra spicy")) > pr chef score1 score2 spiciness total_score above_av 1 anna 1.4142136 -0.7833495 extra spicy 0.3154321 TRUE 2 pierce 0.0000000 0.2611165 spicy 0.1305582 TRUE 3 lisa -0.7071068 -0.7833495 mild -0.7452281 FALSE 4 andy -0.7071068 1.3055824 spicy 0.2992378 TRUE > levels(pr$spiciness) [1] "mild" "spicy" "extra spicy" > levels(pr$spiciness) = c("mild", "medium", "hot") > pr chef score1 score2 spiciness total_score above_av 1 anna 1.4142136 -0.7833495 hot 0.3154321 TRUE 2 pierce 0.0000000 0.2611165 medium 0.1305582 TRUE 3 lisa -0.7071068 -0.7833495 mild -0.7452281 FALSE 4 andy -0.7071068 1.3055824 medium 0.2992378 TRUE