Read in one (or more) of the following data sets, using the correct R package and command.
got_marriages.csv
fish_encounters dataset (available in the tidyr package)
got_like_dislike.csv
Find the _data folder, located inside the posts folder. Then you can read in the data, using base read.csv or read_csv standard tidy read command to read Comma Separated Values files or, alternatively, read the data in directly from loading a package.
Code
library(readr)
Warning: package 'readr' was built under R version 4.1.3
Rows: 255 Columns: 5
-- Column specification --------------------------------------------------------
Delimiter: ","
chr (5): From, To, Type, Notes, Generation
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(got_marriages)
# A tibble: 6 x 5
From To Type Notes Generation
<chr> <chr> <chr> <chr> <chr>
1 Targaryen Stark Married R+L=J Current
2 Baratheon Martell Engaged died Current
3 Baratheon Stark Engaged broken Current
4 Martell Essos Married <NA> Current
5 Martell Reach Affair <NA> Current
6 Martell Essos Affair <NA> Current
Create a Network
Load the package igraph and create an igraph object (i.e. a graph or network) in the form of an edge list. The command may vary whether the data is given as a list of connections or an adjacency matrix. Is the network directed or undirected; weighted or unweighted; unimodal or bipartite? Can you plot it?
Code
library(igraph)
Warning: package 'igraph' was built under R version 4.1.3
Attaching package: 'igraph'
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Code
network.ig <-graph_from_data_frame(got_marriages, directed =TRUE)# Check if the network is directed or undirected, weighted or unweighted, unimodal or bipartiteis_bipartite(network.ig)
[1] FALSE
Code
is_weighted(network.ig)
[1] FALSE
Code
is_directed(network.ig)
[1] TRUE
Code
plot(network.ig)
Source Code
---title: "Week 1 Challenge"author: "Mani Kanta Gogula"description: "Loading Data and Creating a Network"date: "02/13/2023"format: html: toc: true code-fold: true code-copy: true code-tools: true# editor: visualcategories: - challenge_1 - instructions---```{r}#| label: setup#| include: false```## Challenge OverviewToday's challenge is to1) read in a dataset, and2) create a network object## Load the DataRead in one (or more) of the following data sets, using the correct R package and command.- got_marriages.csv- fish_encounters dataset (available in the `tidyr` package)- got_like_dislike.csvFind the `_data` folder, located inside the `posts` folder. Then you can read in the data, using base `read.csv` or `read_csv` standard tidy read command to read Comma Separated Values files or, alternatively, read the data in directly from loading a package.```{r}library(readr)got_marriages <-read_csv("_data/got/got_marriages.csv")head(got_marriages)```## Create a NetworkLoad the package `igraph` and create an `igraph` object (i.e. a graph or network) in the form of an edge list. The command may vary whether the data is given as a list of connections or an adjacency matrix. Is the network directed or undirected; weighted or unweighted; unimodal or bipartite? Can you plot it?```{r}library(igraph)network.ig <-graph_from_data_frame(got_marriages, directed =TRUE)# Check if the network is directed or undirected, weighted or unweighted, unimodal or bipartiteis_bipartite(network.ig)is_weighted(network.ig) is_directed(network.ig) plot(network.ig)```