CSV in r markdown

593 views Asked by At

screenshot of my csv file How would I organize the data from https://users.stat.ufl.edu/~winner/data/sexlierel.dat to make an accurate analysis? I am having trouble plotting the different types of data with the way it is given to me.

description: https://users.stat.ufl.edu/~winner/data/sexlierel.txt

```{r}
data_set <- read.csv("project_data.csv", header = TRUE)

names(data_set)

summary(data_set)

summary(data_set$Gender)

data=data.frame("Gender","Count")

```

I am trying to find the relationship with a scatterplot between the number of people in each category (count). I feel like this is difficult to do with the way the data is given. Is there a way I should rearrange my csv file?

```{r}
scatter=ggplot(data=data, aes("Gender", "Count")) + geom_point()
```
2

There are 2 answers

2
CALUM Polwart On

I don't think that data is a "true" CSV file. There are no commas or other delimiters.

you may need to look at read.tsv which is tab separated data?

0
Michael Dewar On

As @CALUM Polwart said, this is not a comma separated file. It is a fixed width file. You can also consider spaces as the delimiter. There are many packages with functions that can help. For example, you could use

library(data.table)
data_set <- fread("so/sexlierel.txt")

or

library(tidyverse)
data_set <- readr::read_table("so/sexlierel.txt")

You may want to set the column names when you read it. You could use

library(tidyverse)
data_set <- readr::read_table("so/sexlierel.txt", col_names = c("gender", "scale", "psm", "ptl", "religiosity", "count"))

or

library(tidyverse)
data_set <- readr::read_table("so/sexlierel.txt")
names(data_set) <- c("gender", "scale", "psm", "ptl", "religiosity", "count")