Not all columns appearing from SPSS dataset imported. Newbie to R Studio and SPSS way to fix that?

I imported a dataset from the Pew Research Center https://www.journalism.org/dataset/spring-2018-survey-on-factual-and-opinion-statements-in-the-news/. It's an SPSS format which I've never worked with before. I imported the dataset into R Studio as "Import from SPSS" file (I know previous people who have posted here imported to CSV). The data was taken from a survey. And I can't see every column that I know was a survey question asked. I know previous forum posts said R Studio can only handle 100 columns, but mine currently has 158. Some of the questions were "check all that apply" and they've been separated into multiple columns for the one question. Do you recommend:

  1. Combine the "check all that apply" columns into one column for each question? Is that possible?
  2. I delete columns I don't want or need?
  3. OR is there a way to import the dataset to come in with all columns at once?

If I do any of the above or something else, will it start to show the columns? I’ve tried re-importing it, and the attached screenshot is what the end of the dataset looks like. Do you have any ideas? Thank you so much in advance!!

There is not a 100 column limit in R. I think there is a limit on how many columns can be viewed at one time. Here is a data frame with 500 columns.

MAT <- matrix(1:5000, ncol= 500)
DF <- as.data.frame(MAT)
ncol(DF)
#> [1] 500

Created on 2019-12-07 by the reprex package (v0.3.0.9000)
I suggest you run your data frame through the ncol() function and see if all of the columns are there.

It is possible that the data are not being imported correctly. It is hard to debug such problems without access to the data. Please at least describe the data and show the code you are using to import it. Providing access to the data would be ideal.

It won't allow me to upload the .sav file here for others to view and have access to. But it's in the link I included above- on the righthand side of the website- it gives you options to download the data. I tried the ncol function, and it gave me 158 columns. The data comes from a survey. It has a row for each person answering the question, and each column corresponds to a question. And the data in each cell is the person's answer to the column's question-- a number corresponding to the person's answer. The 158th column in the data is not the last question I can see on the survey. I didn't use any code to import it in R Studio. I used the drop down menu on the File menu to --> Import Dataset--> From SPSS.

I'm only looking for 4 columns, and I have 2 out of the 4 included in the import. Based on the picture I included above, I've gotten feedback that: "It looks like there are variables that have a lot of missing data. Create a new file to import that only contains the variables of interest, and then using the appendix in the final project to help with deleting rows that have missing data after you import the new file."

I know you can skip columns in CSV and text files. Is there a way in SPSS to skip columns and just import the columns I want?

I suggest you try using some code like the following. The _foreign_package is included with the base R installation. You import the file (I made up a file name) as a data frame and then select the columns you want either by their numeric index or by their name.

library(foreign)
DF <- read.spss("MyFileName", to.data.frame = TRUE)

#Example of choosing columns by their numeric index
DFclean <- DF[, c(1, 5, 45, 123)]

#Example of choosing columns by name
DFclean <- DF[, c("Name1", "Name2", "Name3", "Name4")]

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.