Program R Flashcards

1
Q

sqrt(36)=6

A

abs(-16)=16

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

?sqrt

A

this code will return the manual of sqrt

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

if some variable name is not built, we can create them. i.e. type “squareroot2=sqrt(2)” then enter, then next time, when we type in squareroot2, the R will return the value 1.414… here is we don’t use “=”, we can also use “

A

lower case and capital letter makes differences when we write the codes in R.

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

ls(), this will return a list of created variable names.

A

no space in variable names. i.e. Square Root is not correct.
don’t put number at the beginning of a variable name. i.e. 2SquareRoot is not correct.
but it’s allowed to put comma in the middle of a variable name i.e. Square2.Root is okay.

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

we can also create a victor, a list of numbers or characters. but cannot have them at the same time.
i.e. we can type in “Country = c(“Brazil”,”China”,”India”,”Switzerland”,”USA”)”, or “LifeExpectancy = c(74,76,65,83,79)”. then when we enter “Country” or “LifeExpectancy” then click on enter, the R will give us the list of country names and the numbers.

A

when there is victor, we type in the name “Country [1]” then enter, the R will give us the first country name in the list.

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

seq(0,100,2) will give us the numbers from 0 to 100 with increase by 2. i.e. 0, 2, 4, 6, ….100

A

we can also create a data frame.
type “CountryData = data.frame(Country,LifeExpectancy)”,
then in next line, type CountryData, the R will give us two columns of data with combined established country names and life expectancy ages. then if in next line, we type CountryData$Population=c(199000,1390000,1240000,7997,318000), then next line type CountryData, R will give us a data frame with 3 columns, with added population numbers.

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

variable “rbind” can combine lines with the same columns and headers of columns.

A

to combine two victors into a data frame, we use data.frame function. i.e. ….=data.frame(x,y)
to add a variable to the data frame, use dollar sign function. i.e. CountryData$Population=c(…,…)
to add a new observation to a data frame, use rbind function. i.e. ….=rbind(x,y)

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

WHO = read.csv(“WHO.csv”)
enter “str(WHO)”
R wil give us the data structure of the WHO file

A

Factor variables are categorical variables that can be either numeric or string

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

function “summary” can give us a summary of a data

A

use “write.csv” can save a data file in the writing directory based on instructions. i.e. write.csv(WHO_Europe,”WHO_Europe.csv”)

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

use “rm(…)” function to remove an created variable

A

in the summary, if there is “NA’s”, it means some data are missing

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

what is time format in R?

A

Month/day/year/ hour and minute

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

how to extract the month and dates in R?

A

here “mvt” is the name of the file. “DateConvert” is the data frame that contains the converted dates.
mvt$Month = months(DateConvert)
mvt$Weekday = weekdays(DateConvert)

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

how to create a table in R with one column of data?

A

table(mvt$Month)

there mvt is the name of the file, Month is the name of the column containing the data

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

how to create a histogram?

A

hist(mvt$Date, breaks=100)

mvt is the file, date is the data.

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