install.packages("swirl")
https://github.com/swirldev/swirl_courses#swirl-courses
https://en.wikipedia.org/wiki/YAML
http://yaml.org/
| 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.
| Let's get started!
sqrt() function and to take the absolute value, use the abs() function
Vector of unequal length Artihmetic Operations
If the vectors are of different lengths,
| R 'recycles' the shorter vector until it is the same length as the longer vector.
| When we did z * 2 + 100 in our earlier example, z was a vector of length 3, but technically 2
| and 100 are each vectors of length 1.
...
|========================================================================== | 76%
| Behind the scenes, R is 'recycling' the 2 to make a vector of 2s and the 100 to make a vector
| of 100s. In other words, when you ask R to compute z * 2 + 100, what it really computes is
| this: z * c(2, 2, 2) + c(100, 100, 100).
Shortcuts
In many programming environments, the up arrow will cycle through previous commands. Try
| hitting the up arrow on your keyboard until you get to this command (z * 2 + 100), then
| change 100 to 1000 and hit Enter. If the up arrow doesn't work for you, just type the
| corrected command.
| You can type the first two letters of the variable name, then hit the Tab key (possibly more
| than once). Most programming environments will provide a list of variables that you've
| created that begin with 'my'. This is called auto-completion and can be quite handy when you
| have many variables in your workspace. Give it a try. (If auto-completion doesn't work for
| you, just type my_div and press Enter.)
List all the files in your working directory using list.files() or dir().
Use dir.create() to create a directory in the current working directory called "testdir".
> dir.create("testdir")
Create a file in your working directory called "mytest.R" using the file.create() function.
>
> file.create("mytest.R")
list.files() shows that the directory only contains mytest.R.
> list.files()
| Create a directory in the current working directory called "testdir2" and a subdirectory for
| it called "testdir3", all in one command by using dir.create() and file.path().
> dir.create(file.path('testdir2','testdir3'))
Warning message:
In dir.create(file.path("testdir2", "testdir3")) :
cannot create dir 'testdir2\testdir3', reason 'No such file or directory'
| You're close...I can feel it! Try it again. Or, type info() for more options.
| dir.create(file.path('testdir2', 'testdir3'), recursive = TRUE) will do the trick. If you
| forgot the recursive argument, the command may have appeared to work, but it didn't create
| the nested directory.
> dir.create(file.path('testdir2','testdir3'),recursive = TRUE)
That gave us every integer between (and including) 1 and 20. We could also use it to create a
| sequence of real numbers. For example, try pi:10.
> pi:10
| Remember that if you have questions about a particular R function, you can access its
| documentation with a question mark followed by the function name: ?function_name_here.
| However, in the case of an operator like the colon used above, you must enclose the symbol in
| backticks like this: ?`:`. (NOTE: The backtick (`) key is generally located in the top left
| corner of a keyboard, above the Tab key. If you don't have a backtick key, you can use
| regular quotes.)
This gives us the same output as 1:20. However, let's say that instead we want a vector of
| numbers ranging from 0 to 10, incremented by 0.5. seq(0, 10, by=0.5) does just that. Try it
| out.
| Another option is to use seq(along.with = my_seq).
If we're interested in creating a vector that contains 40 zeros, we can use rep(0, times =
| 40). Try it out.
> rep(0,time = 40)
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
| Try again. Getting it right on the first try is boring anyway! Or, type info() for more
| options.
| Type rep(0, times = 40) to make a vector containing 40 zeros.
> rep(0,times = 40)
Right now, my_char is a character vector of length 3. Let's say we want to join the elements
| of my_char together into one continuous character string (i.e. a character vector of length
| 1). We can do this using the paste() function.
...
|====================================================== | 63%
| Type paste(my_char, collapse = " ") now. Make sure there's a space between the double quotes
| in the `collapse` argument. You'll see why in a second.
> paste(my_char,collapse = " ")
For a slightly more complicated example, we can join two vectors, each of length 3. Use
| paste() to join the integer vector 1:3 with the character vector c("X", "Y", "Z"). This time,
| use sep = "" to leave no space between the joined elements.
> paste(c(1:3),c("X","Y","Z"),sep = "")
[1] "1X" "2Y" "3Z"
| That's a job well done!
https://github.com/swirldev/swirl_courses#swirl-courses
https://en.wikipedia.org/wiki/YAML
http://yaml.org/
| 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.
| Let's get started!
sqrt() function and to take the absolute value, use the abs() function
Vector of unequal length Artihmetic Operations
If the vectors are of different lengths,
| R 'recycles' the shorter vector until it is the same length as the longer vector.
| When we did z * 2 + 100 in our earlier example, z was a vector of length 3, but technically 2
| and 100 are each vectors of length 1.
...
|========================================================================== | 76%
| Behind the scenes, R is 'recycling' the 2 to make a vector of 2s and the 100 to make a vector
| of 100s. In other words, when you ask R to compute z * 2 + 100, what it really computes is
| this: z * c(2, 2, 2) + c(100, 100, 100).
Shortcuts
In many programming environments, the up arrow will cycle through previous commands. Try
| hitting the up arrow on your keyboard until you get to this command (z * 2 + 100), then
| change 100 to 1000 and hit Enter. If the up arrow doesn't work for you, just type the
| corrected command.
| You can type the first two letters of the variable name, then hit the Tab key (possibly more
| than once). Most programming environments will provide a list of variables that you've
| created that begin with 'my'. This is called auto-completion and can be quite handy when you
| have many variables in your workspace. Give it a try. (If auto-completion doesn't work for
| you, just type my_div and press Enter.)
List all the files in your working directory using list.files() or dir().
Use dir.create() to create a directory in the current working directory called "testdir".
> dir.create("testdir")
Create a file in your working directory called "mytest.R" using the file.create() function.
>
> file.create("mytest.R")
list.files() shows that the directory only contains mytest.R.
> list.files()
| Create a directory in the current working directory called "testdir2" and a subdirectory for
| it called "testdir3", all in one command by using dir.create() and file.path().
> dir.create(file.path('testdir2','testdir3'))
Warning message:
In dir.create(file.path("testdir2", "testdir3")) :
cannot create dir 'testdir2\testdir3', reason 'No such file or directory'
| You're close...I can feel it! Try it again. Or, type info() for more options.
| dir.create(file.path('testdir2', 'testdir3'), recursive = TRUE) will do the trick. If you
| forgot the recursive argument, the command may have appeared to work, but it didn't create
| the nested directory.
> dir.create(file.path('testdir2','testdir3'),recursive = TRUE)
That gave us every integer between (and including) 1 and 20. We could also use it to create a
| sequence of real numbers. For example, try pi:10.
> pi:10
| Remember that if you have questions about a particular R function, you can access its
| documentation with a question mark followed by the function name: ?function_name_here.
| However, in the case of an operator like the colon used above, you must enclose the symbol in
| backticks like this: ?`:`. (NOTE: The backtick (`) key is generally located in the top left
| corner of a keyboard, above the Tab key. If you don't have a backtick key, you can use
| regular quotes.)
This gives us the same output as 1:20. However, let's say that instead we want a vector of
| numbers ranging from 0 to 10, incremented by 0.5. seq(0, 10, by=0.5) does just that. Try it
| out.
| Another option is to use seq(along.with = my_seq).
If we're interested in creating a vector that contains 40 zeros, we can use rep(0, times =
| 40). Try it out.
> rep(0,time = 40)
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
| Try again. Getting it right on the first try is boring anyway! Or, type info() for more
| options.
| Type rep(0, times = 40) to make a vector containing 40 zeros.
> rep(0,times = 40)
Right now, my_char is a character vector of length 3. Let's say we want to join the elements
| of my_char together into one continuous character string (i.e. a character vector of length
| 1). We can do this using the paste() function.
...
|====================================================== | 63%
| Type paste(my_char, collapse = " ") now. Make sure there's a space between the double quotes
| in the `collapse` argument. You'll see why in a second.
> paste(my_char,collapse = " ")
For a slightly more complicated example, we can join two vectors, each of length 3. Use
| paste() to join the integer vector 1:3 with the character vector c("X", "Y", "Z"). This time,
| use sep = "" to leave no space between the joined elements.
> paste(c(1:3),c("X","Y","Z"),sep = "")
[1] "1X" "2Y" "3Z"
| That's a job well done!
LETTERS is a predefined variable
| in R containing a character vector of all 26 letters in the English alphabet.
To make things a little more interesting, lets create a vector containing 1000 draws from a
| standard normal distribution with y <- div="" rnorm="">
> y <- div="" rnorm="">
->
| That's a job well done!
|========================== | 30%
| Next, let's create a vector containing 1000 NAs with z <- 1000="" div="" rep="">
->
> z <- 1000="" div="" rep="">
->
| That's correct!
|============================== | 35%
| Finally, let's select 100 elements at random from these 2000 values (combining y and z) such
| that we don't know how many NAs we'll wind up with or what positions they'll occupy in our
| final vector -- my_data <- 100="" c="" div="" sample="" y="" z="">
->
> my_data <- 100="" c="" div="" sample="" y="" z="">->
In our previous discussion of logical operators, we introduced the `==` operator as a method
| of testing for equality between two objects. So, you might think the expression my_data == NA
| yields the same results as is.na(). Give it a try.
> my_data==NA
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[61] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[91] NA NA NA NA NA NA NA NA NA NA
| Keep up the great work!
|==================================================== | 60%
| The reason you got a vector of all NAs is that NA is not really a value, but just a
| placeholder for a quantity that is not available. Therefore the logical expression is
| incomplete and R has no choice but to return a vector of the same length as my_data that
| contains all NAs.
x[!is.na(x) & x > 0]
Now, let's check that vect and vect2 are the same by passing them as arguments to the
| identical() function.
> identical(vect,vect2)
Now we'll use the cbind() function to 'combine columns'. Don't worry about storing the result
| in a new variable. Just call cbind() with two arguments -- the patients vector and my_matrix.
> cbind(patients,my_matrix)
patients
[1,] "Bill" "1" "5" "9" "13" "17"
[2,] "Gina" "2" "6" "10" "14" "18"
[3,] "Kelly" "3" "7" "11" "15" "19"
[4,] "Sean" "4" "8" "12" "16" "20"
| You are quite good my friend!
Subsetting Function
http://www.statmethods.net/management/subset.html
http://stackoverflow.com/questions/3445590/how-to-extract-a-subset-of-a-data-frame-based-on-a-condition-involving-a-field
->
Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
oracle online training
hadoop training in chennai
hadoop training in bangalore