helpneededthankyou
helpneededthankyou

Reputation: 43

Code Chunk Error: attempt to use zero-length variable name

I'm trying to use a code chunk but I keep getting this error: Error: attempt to use zero-length variable name

enter image description here

#install.packages("tidyverse")
library(ggplot2)
#install.packages("rmarkdown")
library(rmarkdown)

```{r, echo=FALSE}
ggplot(Men_DF, mapping=aes(x=height,y=emails))+geom_point(size=1)
``` 

This is what the data set looks likeenter image description here

Does anyone know why I'm getting this error?

dput(head(Men_DF, 10))
structure(list(emails = c(1L, 3L, 9L, 5L, 19L, 0L, 2L, 3L, 1L, 
4L), rating = c(0.6125247, -0.100942, 0.2975212, -0.0284386, 
0.4072408, -0.3510217, -0.0468019, -0.7681106, -0.4641442, 0.2387305
), height = c(71.5, 67.5, 69.5, 69.5, 69.5, 75.5, 71.5, 65.5, 
69.5, 69.5), bmi = c(29.56526, 27.00137, 25.4697, 26.92511, 24.01428, 
25.28222, 25.43987, 31.95268, 22.55887, 26.92511), yrs_education = c(14, 
18, 16, 21, 21, 14, 16, 17.5, 17.5, 12.5), age = c(3L, 1L, 3L, 
1L, 3L, 2L, 2L, 2L, 1L, 2L), days_active = c(8L, 74L, 30L, 67L, 
61L, 70L, 20L, 108L, 108L, 43L)), row.names = c(NA, 10L), class = "data.frame")


> str(Men_DF)
'data.frame':   1507 obs. of  7 variables:
 $ emails       : int  1 3 9 5 19 0 2 3 1 4 ...
 $ rating       : num  0.6125 -0.1009 0.2975 -0.0284 0.4072 ...
 $ height       : num  71.5 67.5 69.5 69.5 69.5 75.5 71.5 65.5 69.5 69.5 ...
 $ bmi          : num  29.6 27 25.5 26.9 24 ...
 $ yrs_education: num  14 18 16 21 21 14 16 17.5 17.5 12.5 ...
 $ age          : int  3 1 3 1 3 2 2 2 1 2 ...
 $ days_active  : int  8 74 30 67 61 70 20 108 108 43 ...

Upvotes: 0

Views: 647

Answers (1)

emr2
emr2

Reputation: 1722

It could be a problem of the environment. I have just reloaded everything as you edited in the post and I don't have problems..

---
title: "Untitled"
author: "Author"
date: "8/1/2022"
output: html_document
---
```{r}
Men_DF <- structure(list(emails = c(1L, 3L, 9L, 5L, 19L, 0L, 2L, 3L, 1L, 
4L), rating = c(0.6125247, -0.100942, 0.2975212, -0.0284386, 
0.4072408, -0.3510217, -0.0468019, -0.7681106, -0.4641442, 0.2387305
), height = c(71.5, 67.5, 69.5, 69.5, 69.5, 75.5, 71.5, 65.5, 
69.5, 69.5), bmi = c(29.56526, 27.00137, 25.4697, 26.92511, 24.01428, 
25.28222, 25.43987, 31.95268, 22.55887, 26.92511), yrs_education = c(14, 
18, 16, 21, 21, 14, 16, 17.5, 17.5, 12.5), age = c(3L, 1L, 3L, 
1L, 3L, 2L, 2L, 2L, 1L, 2L), days_active = c(8L, 74L, 30L, 67L, 
61L, 70L, 20L, 108L, 108L, 43L)), row.names = c(NA, 10L), class = "data.frame")

```


```{r}
#install.packages("tidyverse")
library(ggplot2)
#install.packages("rmarkdown")
library(rmarkdown)
```

```{r, echo=FALSE}
ggplot(Men_DF, mapping=aes(x=height,y=emails))+geom_point(size=1)
``` 

image

Upvotes: 1

Related Questions