With R Markdown, you can include code chunks like this:
getwd()
## [1] "/Users/rithika/Google Drive/Penn/TA/Intro to DS/Rk_Recitation/Other Files"
setwd("/Users/rithika/Google\ Drive/Penn/TA/Intro\ to\ DS/Rk_Recitation/Data")
#insert the path of the directory of your choice
country.profile <- read.csv("country_profile_variables.csv")
On markdown, you will also see that when you write a function within the code chunk, it will throw out the output automatically after it. Like this
# this will only display the summary for the first 3 columns in the dataset
summary(country.profile[,1:3])
## country Region Surface.area..km2.
## Afghanistan : 1 Caribbean : 25 -99 : 3
## Albania : 1 EasternAfrica : 19 180 : 2
## Algeria : 1 WesternAsia : 18 457 : 2
## American Samoa: 1 SouthernEurope: 16 ~0 : 1
## Andorra : 1 WesternAfrica : 16 1002000: 1
## Angola : 1 SouthAmerica : 14 100284 : 1
## (Other) :223 (Other) :121 (Other):219
You can also choose to not display an R code chunk. echo = FALSE parameter can be added to the code chunk to prevent printing of the R code.
## [1] "factor"
Use the knit button at the top to knit to PDF