R shortcuts Flashcards

shortcut

1
Q

cmd + shft + c

A

To comment multiple code in R studio

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

u can use both for assigment?

A

equality and < sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

?funcname does what?

A

open windows with what the function does

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ls() list what?

A

list of all of the objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

rm() ? What differ list and remove functions?

A

remove object that we dont want e.g rm(x,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to remove all objects at once?

A

rm(list=ls())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

?matrix ?

A

The help file reveals that the matrix() function takes a number of inputs, but for now we focus on the first three: the data (the entries in the matrix), the number of rows, and the number of columns. First, we create a simple matrix

x=matrix(data=c(1,2,3,4), nrow=2, ncol=2)

Note that we could just as well omit typing data=, nrow=, and ncol= in the matrix() command above: that is, we could just type
> x=matrix(c(1,2,3,4) ,2,2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

by default matrix create by colum, how to create it by rows?

A

R creates matrices by successively filling in columns. Alternatively, the byrow=TRUE option can be used to populate the matrix in order of the rows.
> matrix(c(1,2,3,4),2,2,byrow=TRUE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

sqrt(x)

A

calculate squaroot of X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

rnorm()

A

generates a vector of random normal variables, with first argument n the sample size. Each time we call this function, we will get a different answer.

By default, rnorm() creates standard normal random variables with a mean of 0 and a standard deviation of 1. However, the mean and standard devi- ation can be altered using the mean and sd arguments, as illustrated above

x=rnorm(50)
y=x+rnorm(50,mean=50,sd=.1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how to use set.seed() to create same random result ?

A

Sometimes we want our code to reproduce the exact same set of random numbers; we can use the set.seed() function to do this. The set.seed() function takes an (arbitrary) integer argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Plot

A

plot() function is the primary way to plot data in R

passing in the argument xlab will result in a label on the x-axis.

> plot(x,y)
plot(x,y,xlab=”this is the x-axis”,ylab=”this is the y-axis”,
main=”Plot of X vs Y”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

dev.off() it does what?

A

dev.off() indicates to R that we are done creating the plot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

seq(a,b)

A

creates sequence of numbers

seq(0,1,length=10) makes a sequence of 10 numbers that are equally spaced between 0 and 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

indexing A[2,3]

A

The first number after the open-bracket symbol [ always refers to the row, and the second number always refers to the column.

A[c(1,3),c(2,4)]
A[1:3,2:4]
A [1:2 ,]
A [ ,1:2]

The last two examples include either no index for the columns or no index for the rows. These indicate that R should include all columns or all rows, respectively. R treats a single row or column of a matrix as a vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A[-c(1,3),] What does this means ?

A

The use of a negative sign - in the index tells R to keep all rows or columns except those indicated in the index.

17
Q

dim (A)?

A

The dim() function outputs the number of rows followed by the number of columns of a given matrix.

18
Q

read.table() ?

A

primary way to import data

19
Q

write.table() ?

A

We can use the function write.table() to export data.

20
Q

What is data frame?

A

R store objects in a form called Data Frame

21
Q

persp() can be use to create three dimentional plot

A

persp() can be used to produce a three-dimensional

plot.

22
Q

Option + ‘-‘?

A

shorcut for input operator in r

23
Q

read.csv()

A

easiest way to load data in R

24
Q

hearder = T in read.csv why ?

A

Using the option header=T (or header=TRUE) in the read.table() function tells R that the first line of the file contains the variable names,

25
Q

na.strings in read.csv why ?

A

na.strings tells R that any time it sees a particular character or set of characters (such as a question mark), it should be treated as a missing element of the data matrix

26
Q

e na.omit(

Auto=na.omit(Auto)

A

There are various ways to deal with the missing data. In this case, only five of the rows contain missing observations, and so we choose to use the na.omit() function to simply remove these rows.

27
Q

names() function what it is used?

A

use to print names of the variable names

28
Q

Why variables use $? and what is diff $ and attach()

A

To refer to a variable, we must type the data set and the variable name joined with a $ symbol

Alternatively, we can use the attach() function in order to tell R to make the variables in this data frame available by name

> plot(Auto$cylinders , Auto$mpg )
attach(Auto)
plot(cylinders , mpg

29
Q

how to convert quantitative variavle to qualitative variables?

A

The as.factor() function converts quantitative variables into qualitative variables.

cylinders=as.factor(cylinders)

The cylinders variable is stored as a numeric vector, so R has treated it as quantitative. However, since there are only a small number of possible values for cylinders, one may prefer to treat it as a qualitative variable

30
Q

hist()

A

can be use to create histogram

e.g his(mpeg , )

31
Q

pairs()

A

creates scatter plot matrix

32
Q

summary() function ?

A

The summary() function produces a numerical summary of each variable in a particular data set. we can also produce summary of a single variable

33
Q

exiting R how ?

A

type q()

34
Q

savehistory()

A

Before exiting R, we may want to save a record of all of the commands that we typed in the most recent session; this can be accomplished using the savehistory() function

35
Q

loadhistory()

A

Next time we enter R, we can load that history using the loadhistory() function.