首页 > 代码库 > 08/07/2017 R
08/07/2017 R
from today,i will learn something about the R.
install R studio
code:
1.>install.packages("swirl")
>library(swirl)##this sentence just for using of the swirl package.
>swirl()##for the beginning of the swirl
2.select the basic building blocks. If at any point you‘d like more information on a paticular topic,you can type the help.start() at the prompt. when you input
"help.start()",there are some resources for you about the problem. (at some moment ,i i will try it )
R can be used as a simple caculatorjust like " > 5 + 7",then press the enter,you will get the result.
x <- 5 + 7.#there is a single space between two elements(<- is one element).And at this time, R thinks that you do not use the result immediately.so,when you write the x <- 5 + 7,and then you put the enter button,there is not a result.if you want a result ,you should write down the x,then click(press) the enter button.In other words,to view the contents of the variable x,just type x and press enter.
Then type y <- x - 3. then type y,you will find that the result is 9. so x and y can be used in the next time because they are variables.
To create a vector(a small collection of numbers),please type c(),which stands for "concatenate" or "combination".For example,To create a vector that containing the numbers 1.1,9 and 3.14,type c(1.1,9,3.14).
3.any time you have some questions about a particular function,for example ,you want to get more information about the c(),,just type ?c.
>z <- c(1.1,9,3.4)#make a vector and z stores the result.
type z to view its contents. The result is like that 1.10 9.00 3.14. Notice that there are no commas seperating the values in the output.
And you can combine the vetors to make a new vector.For example,type c (z,5.55) ,the result is like that 1.10 9.00 3.14 5.55.
> z * 2 + 100 #Firstly,R mutiplied each of the 3 elements in z by 2..Then it added 100 to each of the elements.
the result of the sqrt(z) is the same as z0.5.
my_sqrt <- sqrt(z-1) my_div <- z / my_sqrt. the result of this format is that the first element of my_div is equal to the first element of z divided by the first element of my_sqrt,and so on...
when you ask R to compute Z * 2 + 100,what it really compute is this :z * c(2,2,2) + c(100,100,100).
When you ask R to compute c(1,2,3,4) + c(0,2)(try),the result is 1 4 3 6
when you ask R to compute c(1,2,3,4) + c(1,2,3),the result is 2 4 7 5 and a waring (because the 3 is not enoug to recycle ).
08/07/2017 R