Data Input and Output Flashcards

1
Q

What are the most basic ways to input data into R?

A

The most basic functions for data input in R are the following:
c( )
rep( )
seq( ) or :

With these basic functions, we can create objects of more specific classes like:

matrix( )
list( )
data.frame( )

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

What’s the basic function to input data from keyboard into a vector?

A

scan( )

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

How can I read character data from keyboard into vector x?

A

x = scan(what = “character”)

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

How can I read the full name of the user from keyboard into a variable called name?

A

name = readLines(n = 1)

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

How can I import a csv called “crabs.csv” into a data frame called df, using the two most common ways?

A

df = read.table(“crabs.csv”, header = TRUE)

or using wrapper function read.csv:

df = read.csv(“crabs.csv”)

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

Once I’ve loaded my data frame called df, now I want to quickly see the basic structure of the dataframe and its first rows of data, what functions should I use?

A

str( df )

and

head( df )

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

Can I use functions read.table and read.csv to read a csv file from a web url?

A

Yes, I just need to provide the full url to the file argument.

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

How do I list the data sets available with R installation and how can I load one of them?

A

data( ) - to list

data( mtcars ) - to load data set mtcards

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

How can I export my data frame Titanic to a csv?

A

write.table(Titanic, “titanic.csv”, row.names=F, sep=”,”, dec=”.”)

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

What function should I use to save a file with text representation of an R object?

A

dput(da) - to output in the console

dput(da, file = “da.R”) - to write a file

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

How can I write text representations of three R objects called ma, da, vec into a file? How can I load them into R later?

A

Write:

dump(c(“ma”, “da”, “vec”), file = “data.R”)

Read:
source(“data.R”)

It creates the objects in your working area with the same names and attributes with which they’ve been stored.

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

What are this function calls doing? Why is it useful.

save(da, file = “dados.rda”)

save(da, ma, file = “dados.rda”)

save.image(file = “workspace.RData”)

load(“dados.rda”) l

load(“workspace.RData”)

A

Saving and loading data in binary format. It’s useful when I only have this option or when I need an absolutely great precision to store numbers.

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

How can I see a list of files present in my working directory?

A

dir( )

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

How can I see information about a file called “word_count.ipynb”? What kinds of information does it return?

A

file.info(“word_counter.ipynb”)

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

How can I check if file word_cloud.txt is present in the directory?

A

file.exists(“word_cloud.txt”)

Returns TRUE or FALSE

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