learning r with swirl -basic building blocks

     First of all, you should know that when you see '...', that means you should press Enter when you are done reading and ready to continue.

    Also, when you see 'ANSWER:', the R prompt (>), or when you are asked to select from a list, that means it's your turn to enter a response, then press Enter to continue.

    You can exit swirl and return to the R prompt (>) at any time by pressing the Esc key.If you are already at the prompt, type bye() to exit and save your progress. When you exit properly, you'll see a short message letting you know you've done so.

    | When you are at the R prompt (>):
| -- Typing skip() allows you to skip the current question.
| -- Typing play() lets you experiment with R on your own; swirl will ignore what you do...
| -- UNTIL you type nxt() which will regain swirl's attention.
| -- Typing bye() causes swirl to exit. Your progress will be saved.
| -- Typing main() returns you to swirl's main menu.
| -- Typing info() displays these options again.

    If at any point you'd like more information on a particular topic related to R, you can type help.start() at the prompt, which will open a menu of resources .

    变量的表示:

                      The way you assign a value to a variable in R is by using the assignment operator, which is just a 'less than' symbol followed by a 'minus' sign. It looks like this: <-。Think of the assignment operator as an arrow. You are assigning the value on the right side of the arrow to the variable name on the left side of the arrow.To assign the result of 5 + 7 to a new variable called x, you type x <- 5 + 7. This can be read as 'x gets 5 plus 7'。

   创建一个矢量(向量):

                      The easiest way to create a vector is with the c() function, which stands for 'concatenate' or 'combine'. To create a vector containing the numbers 1.1, 9, and 3.14, type c(1.1, 9, 3.14). 

   对 函数功能有疑问:

                      Anytime you have questions about a particular function, you can access R's built-in help files via the `?` command. For example, if you want more information on the c() function, type ?c without the parentheses(圆括号) that normally follow a function name. 

                      此时出现的结果是:c{base}  combine values into a vector or list.默认方法将其参数组合成一个向量。所有参数都被强制转换为返回值的普通类型,除名称以外的所有属性都被删除。

    数字矢量同样可以用于数学表达式中,例如

                                                                        z   <- c(1.1,9,3.14)

                                                                        z*2+100

                                       最后回车后的结果是 102.20 118.00 106.28

    在矢量的加减乘除,开方sqrt(),绝对值abs()类运算中,如果两个矢量的长度一致,则分别对其中的每个元素进行相对应的运算,如果矢量的长度不相等,则R将循环较短的那个矢量,使之和较长的那个一样长。

    那么是如何循环的呢?learning r with swirl -basic building blocks

tips:按上键可以回顾你原先输入的内容。




learning r with swirl -basic building blocks