Import your data

data = read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-10-14/food_security.csv")
## Rows: 171232 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Area, Item, Unit, Flag, Note
## dbl (5): Year_Start, Year_End, Value, CI_Lower, CI_Upper
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_small <- data %>%
    select(Item, Area, Value) %>%
    filter(Area %in% c("Afghanistan"))

Pivoting

wide to long form

data <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-10-14/food_security.csv")
## Rows: 171232 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Area, Item, Unit, Flag, Note
## dbl (5): Year_Start, Year_End, Value, CI_Lower, CI_Upper
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
set.seed(1234)
data_small<- data %>%
    select("Item", "Value","Area") %>%
    sample_n(5)

data_wide<- data %>%
pivot_wider(names_from = Item, 
            values_from = Value)

long to wide form

data <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-10-14/food_security.csv")
## Rows: 171232 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Area, Item, Unit, Flag, Note
## dbl (5): Year_Start, Year_End, Value, CI_Lower, CI_Upper
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_longer <- data_small %>%
    pivot_longer(cols =c("Area"),
                 names_to = ("Areas"), 
                 values_to = "Places")

Separating and Uniting

data <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-10-14/food_security.csv")
## Rows: 171232 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Area, Item, Unit, Flag, Note
## dbl (5): Year_Start, Year_End, Value, CI_Lower, CI_Upper
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Separate a column

Unite two columns

Missing Values

data <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-10-14/food_security.csv")
## Rows: 171232 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Area, Item, Unit, Flag, Note
## dbl (5): Year_Start, Year_End, Value, CI_Lower, CI_Upper
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_longer <- data_small %>%
    pivot_longer(cols =c("Area"),
                 names_to = ("Areas"), 
                 values_to = "Places",
                 values_drop_na = TRUE)