jpinfect_pivot {jpinfect}R Documentation

Convert data from wide format to long format for easier analysis

Description

This function pivots a dataset between long and wide formats based on the column count. If the dataset has 5 or fewer columns, it is pivoted to a wide format, keeping 'prefecture', 'year', 'week' and 'date' as fixed identifiers. If the dataset has more than 5 columns, it is pivoted to a long format.

Usage

jpinfect_pivot(dataset)

Arguments

dataset

A data frame containing the columns 'prefecture', 'year', 'week', 'date' and additional columns for diseases and their associated case counts.

Details

- If the dataset has 5 or fewer columns, the function uses 'pivot_wider()' to convert the dataset to a wide format. - If the dataset has more than 5 columns, the function uses 'pivot_longer()' to convert the dataset to a long format. - The function ensures that the columns 'prefecture', 'year', 'week' and 'date' are always present.

Value

A data frame that is pivoted either to a long or wide format, depending on the number of columns. If 'prefecture', 'year', 'week' or 'date' are missing from the dataset, the function stops with an error.

Examples


# Pivot the dataset
result <- jpinfect_pivot(place_prefecture)
print(result)



[Package jpinfect version 0.1.2 Index]