1

I'm trying to import the YRBS ASCII .dat file found here to analyze in R, but I'm having trouble importing the file. I followed the recommendations here and here but none seem to work. More specifically, it's still showing up as being one column/variable in R with 14,765 observations.

I've tried using the readLines(), read.table, and read.csv functions but none seem to be separating the columns.

Here are the specific codes I tried:

readLines("D:/Projects/XXH2017_YRBS_Data.dat", n=5)
read.csv("D:/Projects/XXH2017_YRBS_Data.dat", header = FALSE)
read.table("D:/Projects/XXH2017_YRBS_Data.dat", header = FALSE)

readLines and read.csv only provided one column and I got an error message from using read.table that stated that line 1 did not have 23 elements (which I'm assuming is just referring to the missing values?). The data also starts from line 1 so I cannot use skip = 1 like some have suggested online.

How do I import this file into R so that I can separate the columns?

ssjjaca
  • 219
  • 1
  • 6

0 Answers0