62.5k views
5 votes
Read the data file to a data frame ss16wa, and only retain columns "PWGTP", "AGEP", "WAGP", "VALP", "WKHP", "CIT", "ACCESS". (2) Remove from ss16wa all rows with NA values. (3) Remove from ss16wa all rows where "PWGTP" is greater than 700. (4) Remove from ss16wa all rows where "AGEP" is greater than 87. (5) Remove from ss16wa all rows where "VALP" is less than 2000. (6) Print the dimensions of ss16wa. Hint: they should be 25820 by 7.

User Jay Gajjar
by
6.1k points

1 Answer

7 votes

Answer:

Data Frame

A data frame is used for storing data tables. It is a list of vectors of equal length. For example, the following variable df is a data frame containing three vectors n, s, b.

> n = c(2, 3, 5)

> s = c("aa", "bb", "cc")

> b = c(TRUE, FALSE, TRUE)

> df = data.frame(n, s, b) # df is a data frame

Built-in Data Frame

We use built-in data frames in R for our tutorials. For example, here is a built-in data frame in R, called mtcars.

> mtcars

mpg cyl disp hp drat wt ...

Mazda RX4 21.0 6 160 110 3.90 2.62 ...

Mazda RX4 Wag 21.0 6 160 110 3.90 2.88 ...

Datsun 710 22.8 4 108 93 3.85 2.32 ...

............

The top line of the table, called the header, contains the column names. Each horizontal line afterward denotes a data row, which begins with the name of the row, and then followed by the actual data. Each data member of a row is called a cell.

To retrieve data in a cell, we would enter its row and column coordinates in the single square bracket "[]" operator. The two coordinates are separated by a comma. In other words, the coordinates begins with row position, then followed by a comma, and ends with the column position. The order is important.

Step-by-step explanation:

User CamiloEr
by
5.9k points