︠21229079-fc17-418d-8e74-3c1670766684︠ %md # R jupyter kernel in sage worksheet ︡7d372034-f0f3-4c3b-be60-4016383f6c02︡{"done":true,"md":"\n# R jupyter kernel in sage worksheet"} ︠b357a3fc-7234-4498-a796-c2f4a71a1bb0s︠ %auto ir = jupyter("ir") %default_mode ir ︡1bb793b0-2c4a-455d-887d-7df00222144a︡{"html":"\n\n
\n\n\n\n\n\n\n\n"}︡{"done":true}︡ ︠2e700ab8-b8f3-4c15-a188-87a6a6638a83s︠ R.version.string ︡dd3e5f3c-190b-4787-b639-f6328b74a09c︡{"stdout":"Out [2]: "}︡{"html":"'R version 3.2.2 (2015-08-14)'"}︡{"done":true}︡ ︠20a3bc25-9428-4367-a990-91f91f7a9b17s︠ ax <- c(0,5,8,8) ay <- c(2,3,5,3) df <- data.frame(ax,ay) df ︡c5937007-7af0-4a7a-be26-29cfd9e91159︡{"stdout":"Out [3]: "}︡{"file":{"filename":"/tmp/tmpVifJvz.png","show":true,"text":null,"uuid":"54adffc0-4cc4-4d7b-bf17-1c8f497d89da"},"once":false}︡{"done":true}︡ ︠b51e89b3-c897-4a75-bb02-5f336acb6056s︠ R.version.string ︡201d09b6-6fff-4066-8a28-13fce7347ab6︡{"stdout":"Out [4]: "}︡{"html":"'R version 3.2.2 (2015-08-14)'"}︡{"done":true}︡ ︠27990659-3e69-44cd-a5a4-7d756a828f74︠ # Motor Trend sample data # https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/mtcars.html str(mtcars) ︡706b26c7-b37a-47b3-8c3f-ed113533f87b︡{"html":"
'data.frame':\t32 obs. of 11 variables:\n $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...\n $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...\n $ disp: num 160 160 108 258 360 ...\n $ hp : num 110 110 93 110 175 105 245 62 95 123 ...\n $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...\n $ wt : num 2.62 2.88 2.32 3.21 3.44 ...\n $ qsec: num 16.5 17 18.6 19.4 17 ...\n $ vs : num 0 0 1 1 0 1 0 1 1 1 ...\n $ am : num 1 1 1 0 0 0 0 0 0 0 ...\n $ gear: num 4 4 4 3 3 3 3 4 4 4 ...\n $ carb: num 4 4 1 1 2 1 4 2 2 4 ...\n"}︡{"done":true}︡ ︠4c555028-800c-4cf5-b29d-9b4a7313aa0es︠ # model car mpg as linear function of wt (1000 lbs) and number of cylinders model <- lm(mpg ~ wt + cyl, data = mtcars) summary(model) ︡949fe533-ed23-4a91-8c09-ae1415883b36︡{"stdout":"Out [6]: "}︡{"stdout":"\nCall:\nlm(formula = mpg ~ wt + cyl, data = mtcars)\n\nResiduals:\n Min 1Q Median 3Q Max \n-4.2893 -1.5512 -0.4684 1.5743 6.1004 \n\nCoefficients:\n Estimate Std. Error t value Pr(>|t|) \n(Intercept) 39.6863 1.7150 23.141 < 2e-16 ***\nwt -3.1910 0.7569 -4.216 0.000222 ***\ncyl -1.5078 0.4147 -3.636 0.001064 ** \n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n\nResidual standard error: 2.568 on 29 degrees of freedom\nMultiple R-squared: 0.8302,\tAdjusted R-squared: 0.8185 \nF-statistic: 70.91 on 2 and 29 DF, p-value: 6.809e-12\n"}︡{"done":true}︡ ︠f90eb6ee-f2d7-413f-8c6f-12386c9fd92bs︠ # scatterplots plot(mtcars[c('mpg','wt','cyl')]) ︡84b4ce77-ccb1-4128-8212-a8e893461ce4︡{"file":{"filename":"/tmp/tmpdi6Oes.png","show":true,"text":null,"uuid":"89fadc8c-e2bd-4893-a760-4e08798905dc"},"once":false}︡{"done":true}︡ ︠d1421ecf-5055-4835-826f-5c60ddb84aafs︠ # r error message model2 <- lm(mpg ~ badcol, data = mtcars) ︡1b1a7fa2-c357-48f1-a4ac-807912feee96︡{"html":"
Error in eval(expr, envir, enclos): object 'badcol' not found\nTraceback:\n"}︡{"html":"
1. lm(mpg ~ badcol, data = mtcars)"}︡{"html":"
2. eval(mf, parent.frame())"}︡{"html":"
3. eval(expr, envir, enclos)"}︡{"html":"
4. stats::model.frame(formula = mpg ~ badcol, data = mtcars, drop.unused.levels = TRUE)"}︡{"html":"
5. model.frame.default(formula = mpg ~ badcol, data = mtcars, drop.unused.levels = TRUE)"}︡{"html":"
6. eval(predvars, data, env)"}︡{"html":"
7. eval(expr, envir, enclos)"}︡{"done":true}︡ ︠2af6d903-6982-4aa3-a1ee-731778d94ac6︠ # autocomplete with r jupyter kernel # put cursor at the $ and press TAB # you should see something like the # image in the next cell model$ ︡03109939-74e7-480d-a498-d652e75fe947︡ ︠4448e8f4-d647-47f5-b204-0504a9141513s︠ %sage salvus.file('r-completion.png') ︡5d1fdabe-e725-4639-b53f-d1483a724575︡{"file":{"filename":"r-completion.png","show":true,"text":null,"uuid":"c58ec5c0-da0f-4205-9673-116dec22d014"},"once":false}︡{"done":true}︡ ︠9a8c52cd-45e8-4007-a2a8-dc916a94eab2︠