You are on page 1of 5

R basic shortcuts :-

Alt + f+ n = new script editor window.

type command , highlight it and hit enter (ctrl +R) in r window. <-output

or

window > untitled R editor >

shift + end -<- select the command from point of cursor to right side ...(whole line)

Shift + ctrl +end -<- selec all the lines from the point of cursor to (right) end of script.

shift + alt -<-select the command from point of cursor to left side ...(whole line)

Shift + alt +end -<- selec all the lines from the point of cursor to (right) end of script.

To move to the previous command : - up arrow

Assignment operator <-

ex:

x<- 2

y<- 3

x+y

z<- "hello"

hello
x+z

error!

C combine function :

c(1,2)

12

x<- c(1,2)

x+5

6 7 // it adds 5 +1 and 5+2

all the elements should be of same type .

x<- c("hello num 1","hello num 2")

"hello num 1" "hello num 2"

Shortcut :

45:48

45 46 47 48// same as c(45,46,47,48)

c(45,46,47,48)2

90 92 94 96

object oriented programming in statistics :


> x<-314:320

>x

[1] 314 315 316 317 318 319 320

> length(x)

[1] 7

> x[2]

[1] 315

> y<-x(4:7)

Error in x(4:7) : could not find function "x"

> y<-x[4:7]

>y

[1] 317 318 319 320

> length(x)==length(y)

[1] FALSE

>

Working with data tables in R :

> w<-data.frame(names=c("keerthana","kavya","chinamyi"),age=c(15,14,16))

>w

names age

1 keerthana 15

2 kavya 14

3 chinamyi 16
> w[ , ]

names age

1 keerthana 15

2 kavya 14

3 chinamyi 16

> w[2:3, ]

names age

2 kavya 14

3 chinamyi 16

> w[2:3]

Error in `[.data.frame`(w, 2:3) : undefined columns selected

> w[2]

age

1 15

2 14

3 16

> w[1]

names

1 keerthana

2 kavya

3 chinamyi

> w[1,2]

[1] 15

> w[3,1]

[1] chinamyi
Levels: chinamyi kavya keerthana

> w[2,1]

[1] kavya

Levels: chinamyi kavya keerthana

> w[1,1]

[1] keerthana

Levels: chinamyi kavya keerthana

> w[2,2]

[1] 14

> w[3,2]

[1] 16

>

You might also like