CS代写 Basic R Lab Key

Basic R Lab Key

Basic R Lab Key

Copyright By PowCoder代写 加微信 powcoder

In this lab you can use the interactive console to explore or Knit the document. Remember anything you type here can be “sent” to the console with Cmd-Enter (OS-X) or Cntr-Enter (Windows/Linux) in an R code chunk.

create a new variable called my.num that contains 6 numbers

my.num = c(5,4,7,8,12,14)

mulitply my.num by 4

my.num * 4

## [1] 20 16 28 32 48 56

create a second variable called my.char that contains 5 character strings

my.char = c(“Andrew”, “John”, “John”, “Andrew”,”John”)

combine the two variables my.num and my.char into a variable called both

both = c(my.num, my.char)

what is the length of both?

length(both)

what class is both?

class(both)

## [1] “character”

Divide both by 3, what happens?

## Error in both/3: non-numeric argument to binary operator

create a vector with elements 1 2 3 4 5 6 and call it x

x = c(1,2,3,4,5,6)

create another vector with elements 10 20 30 40 50 and call it y

y = c(10,20,30,40,50)

what happens if you try to add x and y together? why?

## Warning in x + y: longer object length is not a multiple of shorter object

## [1] 11 22 33 44 55 16

append the value 60 onto the vector y (hint: you can use the c() function)

y = c(y, 60)

add x and y together

## [1] 11 22 33 44 55 66

multiply x and y together. pay attention to how R performs operations on vectors of the same length.

## [1] 10 40 90 160 250 360

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com