Skip to main content

Section 2.3 View Function

To check what the imported data looks like, use the view() function. The view() function opens a data viewer window in R, allowing you to interactively explore the contents of a data frame.
view(GSS.2012)
The syntax above displays the contents of the GSS.2012 data frame. If you check the data, you may recognize that each row represents an individual who participated in the survey, and columns represent different variables. For instance, the column labeled as RACE refers to a respondent’s race. You will see five variables included in this dataset: RACE, SEX, POLHITOK, POLABUSE, and AGE. Although many more variables were included in the 2012 GSS, I retained only our variables of interest here to simplify the data management process.
You will see a number below each variable. For instance, respondent’s race (RACE) was coded as 1 = White, 2 = Black, and 3 = Other. SEX represents a respondent’s sex (1 = Male and 2 = Female). POLHITOK represents a respondent’s response to the following question: “Are there any situations you can imagine in which you would approve of a policeman striking an adult male citizen?” The response options for this item were 1 (yes) and 2 (no). POLABUSE represents a respondent’s response to the following question: “Would you approve of a police officer striking a citizen who had said vulgar and obscene things to the policeman?” The response options for this item were also 1 (yes) and 2 (no). Finally, AGE represents a respondent’s age.