Data Utilities Flashcards

1
Q

seq( ) function

A

Generates sequences, by specifying the from, to, and by arguments.

ex: seq(from = 2, to = 8, by = 2)
output: 2 4 6 8

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

rep( )

A

Replicate elements of vectors and lists

ex: rep(c(2,3,4), times = 3)
Output: 234234234

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

sort(x, decreasing = FALSE )

A

Sort a vector in ascending order. Works on numerics, but also on character strings and logicals.

sort(c(5,1,3))
output: 1 3 5

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

str( )

A

Display the structure of any R object.

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

append( )

A

Merge vectors or lists.

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

is.x

A

checks for the specified x class of an R object

is.character(“dog”)
TRUE

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

as.x

A

Convert an R object from one class to another

as.character(4)
“4”

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

grep( pattern, x )

A

Search for matches to argument “pattern” within each element of a character vector. returns the index of elements that match the pattern

ex: grep(pattern = “a”, c(“apple”, “dog”, “cat”))
return: 1 3

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

grepl( pattern, x)

A

Search for matches to argument “pattern” within each element of a character vector. Returns logicals based on whether each element matches the pattern:

ex: grepl(pattern = “a”, c(“apple”, “dog”, “cat”))
return: TRUE FALSE TRUE

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

Regular Expressions: ^

A

match characters that begin with whatever comes after the ^ sign

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

Regular Expressions: $

A

match characters at the end of a string

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

Regular Expressions: .*

A

matches any character (.) zero or more times (*). Both the dot and the asterisk are metacharacters. You can use them to match any character between the at-sign and the “.edu” portion of an email address.

”@.*\.edu$”

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

sub( pattern, replacement, x )

A

Uses the replace argument to replace the first match from the pattern argument

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

gsub( pattern, replacement, x)

A

Uses the replace argument to replace ALL matches from the pattern argument

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

Sys.Date( )

A

returns the current date. returns class “Date”

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

Sys.time( )

A

returns the current date and time. Returns class “POSIXct”