'Why can't I knit RMarkdown?
This is the code that I have, and for some reason I can't knit it.
## R Chunk to Import non-path specific dataset
```{r}
act2 <- read.csv(file="~/actdata_2.csv")
```
## Task 1
```{r}
attach(act2)
school <- rep(0,length(act2$courses))
school[act2$courses>=4.0]<-"fulltime"
school[act2$courses<4.0]<-"parttime"
act2<-data.frame(cbind(act2,school))
table(act2$school)
```
## Task 2
```{r}
employment_status <- table(act2$strategy,act2$job)
barplot(employment_status,beside=TRUE, col=c("red","blue"), xlab = "Studying Strategy", ylab = "Number of participants", legend = TRUE, args.legend = list(x="topright",bty="n"))
```
## Task 3
```{r}
task3 <- select(filter(act2, act2$major=="yes"), major, sleep)
summary(task3)
```
The problem comes up at Task 3, and the error says, could not find function "select". What can I do to knit it?
Solution 1:[1]
Most of the functions you use in this script are base R functions, so you don't need to load a specific package to use them. However, select comes from dplyr, so R doesn't know what the definition of that function is unless you tell it to go look for that function within the package dplyr. There are two ways you can solve this:
Use the
librarycall to load the package whose functions you want to use, e.g. putlibrary(dplyr)at the top of your markdown fileSpecify which package a given function comes from by listing that package name and "::" in front of that function, e.g., the line under "Task 3" would be:
task3 <- dplyr::select(filter(act2, act2$major=="yes"), major, sleep)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shirewoman2 |
