100+ results for 'lang:r pivot_wider'
Not the results you expected?
analysis.R (https://github.com/jkaupp/tidytuesdays.git) R · 61 lines
BSU_plots.R (https://gitlab.com/pjbirrell/real-time-mcmc) R · 50 lines
pivot_wider.R (https://github.com/TysonStanley/tidyfast.git) R · 89 lines
2 #'
3 #'
4 #' \code{dt_pivot_wider()} "widens" data, increasing the number of columns and
5 #' decreasing the number of rows. The inverse transformation is
6 #' \code{dt_pivot_longer()}. Syntax based on the \code{tidyr} equivalents.
23 #' )
24 #'
25 #' dt_pivot_wider(example_dt, names_from = stuff, values_from = things)
26 #' dt_pivot_wider(example_dt, names_from = stuff, values_from = things, id_cols = z)
29 #'
30 #' @export
31 dt_pivot_wider <- function(dt_,
32 id_cols = NULL,
33 names_from,
34 names_sep = "_",
35 values_from) {
36 UseMethod("dt_pivot_wider", dt_)
37 }
functions.R (https://github.com/kjhealy/covdata.git) R · 216 lines
get_tableone.R (https://github.com/openpharma/visR.git) R · 129 lines
105 data_ns <- data %>%
106 dplyr::summarise(summary = dplyr::n()) %>%
107 tidyr::pivot_wider(names_from = tidyselect::any_of(strata), values_from = "summary") %>%
108 dplyr::mutate(variable = "Sample", summary_id = "N")
113 tidyr::pivot_longer(cols = setdiff(names(.), strata), names_to = "variable", values_to = "summary") %>%
114 tidyr::unnest_longer(summary) %>%
115 tidyr::pivot_wider(names_from = tidyselect::any_of(strata), values_from = "summary")
117 data_table1 <- rbind(data_ns, data_summary) %>%
ds_admin.ch.R (https://github.com/covid19datahub/COVID19.git) R · 123 lines
test-embeddings.R (https://github.com/tidymodels/textrecipes.git) R · 352 lines
nzv.R (https://github.com/rstudio-conf-2020/applied-ml.git) R · 113 lines
kids-table.R (https://github.com/gkaramanis/tidytuesday.git) R · 104 lines
lmodel2-tidiers.R (https://github.com/tidymodels/broom.git) R · 113 lines
test-tidyr-pivot-wider.R (https://github.com/rstudio/sparklyr.git) R · 262 lines
8 sdf <- copy_to(sc, tibble::tibble(key = c("x", "y", "z"), val = 1:3))
9 pv <- tidyr::pivot_wider(
10 sdf, names_from = key, values_from = val, names_sort = TRUE
11 ) %>%
20 sdf <- copy_to(sc, tibble::tibble(a = 1, key = c("x", "y"), val = 1:2))
21 pv <- tidyr::pivot_wider(
22 sdf, names_from = key, values_from = val, names_sort = TRUE
23 ) %>%
32 sdf <- copy_to(sc, tibble::tibble(a = 1:2, key = c("x", "y"), val = 1:2))
33 pv <- tidyr::pivot_wider(
34 sdf, names_from = key, values_from = val, names_sort = TRUE
35 ) %>%
1_download_census_data.R (https://github.com/wxwx1993/PM_COVID.git) R · 146 lines
46 acs_data <- get_acs("county", variables = acs_vars, year = year)
47 acs_data$moe <- NULL
48 acs_data <- pivot_wider(acs_data,id_cols = c(GEOID, NAME), names_from = variable, values_from = estimate)
49 }
75 dec_data <- get_decennial("county", variables = dec_vars, year = year)
76 }
77 dec_data <- pivot_wider(dec_data, id_cols = c(GEOID, NAME), names_from = variable, values_from = value)
78 }
Reading.R (https://github.com/beeb22/makeovermonday.git) R · 68 lines
32 reading %>%
33 pivot_wider(names_from = category,
34 values_from = index_2015_100) %>%
35 clean_names() %>%
40 filter(date == as.Date("2015-04-01") | date == as.Date("2020-08-01")) %>%
41 select(country, real_books, date) %>%
42 pivot_wider(names_from = date, values_from = real_books) %>%
43 mutate(change = (`2020-08-01` - `2015-04-01`)*100) %>%
44 ggplot()+
show_group_enrichment.R (https://github.com/ShixiangWang/sigminer.git) R · 194 lines
tidytuesday_201945_bike_and_walk_commutes.r (https://github.com/spren9er/tidytuesday.git) R · 93 lines
kids.R (https://github.com/gkaramanis/tidytuesday.git) R · 56 lines
model_eval.R (https://github.com/microsoft/forecasting.git) R · 50 lines
tidytuesday_201932_bob_ross_paintings.r (https://github.com/spren9er/tidytuesday.git) R · 121 lines
53 filter(painted == 1) %>%
54 select(-painted) %>%
55 pivot_wider(names_from = color_name, values_from = total) %>%
56 replace(is.na(.), 0)
69 dist_mtx <- cut_residuals %>%
70 pivot_wider(object, names_from = color, values_from = cut_residual) %>%
71 column_to_rownames('object') %>%
72 as.matrix() %>%
show_sig_fit.R (https://github.com/ShixiangWang/sigminer.git) R · 86 lines
tidy.R (https://github.com/ikashnitsky/dataviz-mpidr.git) R · 96 lines
narrabri_rose_plants.r (https://github.com/APSIMInitiative/ApsimX.git) R · 74 lines
22 biomass <- read_xlsx(path = path, sheet = "Sheet1", range = "A1:J93")
23 biomass_longer <- biomass %>% pivot_longer(cols = 3:10, names_to = "treatment", values_to = "values")
24 biomass_wider <- biomass_longer %>% pivot_wider(names_from = Variate, values_from = values)
25 biomass_2009 <- biomass_wider %>% mutate(year = "2009") %>% select(year, DAS, everything())
32 biomass <- read_xlsx(path = path, sheet = "Sheet1", range = "A1:J73")
33 biomass_longer <- biomass %>% pivot_longer(cols = 3:10, names_to = "treatment", values_to = "values")
34 biomass_wider <- biomass_longer %>% pivot_wider(names_from = Variate, values_from = values)
35 biomass_2010 <- biomass_wider %>% mutate(year = "2010") %>% select(year, DAS, everything())
44 phenology <- bind_rows(firstsquare, firstflower) %>% select(-Variate) %>% select(year, variable, everything())
45 phenology_longer <- phenology %>% pivot_longer(c(3:10), names_to = "treatment", values_to = "values")
46 phenology_wider <- phenology_longer %>% pivot_wider(names_from = variable, values_from = values)
47 phenology_2009 <- phenology_wider
plot_doublingTime.R (https://github.com/chschoenenberger/covid19_dashboard.git) R · 56 lines
22 daysGrowthRate <- 7
23 data <- data_evolution %>%
24 pivot_wider(id_cols = c(`Province/State`, `Country/Region`, date, Lat, Long), names_from = var, values_from = value) %>%
25 filter(if (input$selectize_doublingTime_Variable == "doublingTimeConfirmed") (confirmed >= 100) else (deceased >= 10)) %>%
26 filter(if (is.null(input$selectize_doublingTime_Country)) TRUE else `Country/Region` %in% input$selectize_doublingTime_Country) %>%
tuber.R (https://github.com/soodoku/tuber.git) R · 129 lines
get_popn_nhs.R (https://gitlab.com/pjbirrell/real-time-mcmc) R · 58 lines
get_video_details.R (https://github.com/soodoku/tuber.git) R · 131 lines
20_PredictorPorts.R (https://github.com/OpenSourceAP/CrossSection.git) R · 117 lines
cochrane2df.R (https://github.com/massimoaria/bibliometrix.git) R · 63 lines
preprocess-contact-rates.r (https://github.com/ImperialCollegeLondon/covid19model.git) R · 159 lines
81 for(period in c("weekend", "weekday")){
83 contact_tab_matrix.c.p <- pivot_wider(contact_tab[[Country]][[period]], id_cols= part.age, names_from = cont.age, values_from = m)
84 stopifnot( all( colnames(contact_tab_matrix.c.p)[-1] == contact_tab_matrix.c.p$part.age ) )
85 contact_tab_matrix[[Country]][[period]] <- unname(as.matrix(contact_tab_matrix.c.p[,-1]))
153 for(Country in countries){
154 contact_tab_matrix.c <- pivot_wider(contact_tab[[Country]], id_cols= part.age, names_from = cont.age, values_from = m)
155 stopifnot( all( colnames(contact_tab_matrix.c)[-1] == contact_tab_matrix.c$part.age ) )
156 contact_tab_matrix[[Country]] <- unname(as.matrix(contact_tab_matrix.c[,-1]))
tsibble2ts.R (https://github.com/tidyverts/tsibble.git) R · 216 lines
tidy-exercises-solutions.R (https://github.com/ikashnitsky/dataviz-mpidr.git) R · 107 lines
37 # - subset only the year 2004
38 # - transform to wide format using the column "sex" (pivot_wider)
39 # - get rid of the column for both sex
40 # - calculate the sex ratio (males to females)
43 pop %>%
44 filter(year == "2004") %>%
45 pivot_wider(names_from = sex, values_from = value) %>%
46 select(-b) %>%
47 mutate(sr = m / f) %>%
71 filter(age %in% 15:59, year == "2001") %>%
72 select(-year, -pop, -deaths) %>%
73 pivot_wider(names_from = sex, values_from = mx) %>%
74 select(-b) %>%
75 mutate(sr_mx = (m / f) %>% na_if(Inf)) %>% # replace Inf with NAs
tidyr-verbs.R (https://github.com/tidyverts/tsibble.git) R · 195 lines
19 }
21 pivot_wider.tbl_ts <- function(data, id_cols = NULL, names_from = name, ...) {
22 key_var <- vars_pull(names(data), !!enquo(names_from))
23 if (has_index(key_var, data)) {
30 new_key <- key_vars(remove_key(data, .vars = key_left))
32 tbl <- tidyr::pivot_wider(as_tibble(data),
33 id_cols = !!enquo(id_cols), names_from = !!enquo(names_from), ...)
34 tbl <- retain_tsibble(tbl, new_key, index(data))
artefact_viewer.R (https://github.com/craddm/eegUtils.git) R · 169 lines
scrape_citydata.R (https://github.com/eeg31/police-reform.git) R · 132 lines
test-verb-pivot-wider.R (https://github.com/hadley/dbplyr.git) R · 212 lines
10 expect_equal(
11 memdb_frame(key = c("x", "y", "z"), val = 1:3) %>%
12 tidyr::pivot_wider(names_from = key, values_from = val) %>%
13 collect(),
14 tibble(x = 1, y = 2, z = 3)
23 expect_snapshot(
24 lazy_frame(key = c("x", "y", "z"), val = 1:3) %>%
25 dbplyr_pivot_wider_spec(spec)
26 )
27 })
32 expect_equal(
33 dbplyr_pivot_wider_spec(df, spec) %>% op_vars(),
34 c("a", "x", "y")
35 )
test-tidyr.R (https://github.com/tidyverts/tsibble.git) R · 146 lines
18 ungroup()
20 test_that("pivot_wider()", {
21 out <- tsbl %>%
22 pivot_wider(names_from = group, values_from = value)
26 out_grp <- tsbl %>%
27 group_by(group) %>%
28 pivot_wider(names_from = group, values_from = value)
29 expect_equal(groups(out_grp), list())
30 out2 <- tourism %>%
31 pivot_wider(names_from = Purpose, values_from = Trips)
32 expect_equal(key_vars(out2), c("Region", "State"))
33 expect_equal(ncol(out2), 7)
broom-package.R (https://github.com/tidymodels/broom.git) R · 30 lines
zzz.R (https://github.com/tidyverts/tsibble.git) R · 24 lines
taylor-swift-beyonce.R (https://github.com/rfordatascience/tidytuesday.git) R · 139 lines
21 separate(album_details, into = c("album_detail_type", "album_details"), sep = ": ") %>%
22 mutate(album_detail_type = if_else(album_detail_type == "Re-edition", "Re-release", album_detail_type)) %>%
23 pivot_wider(names_from = album_detail_type, values_from = album_details) %>%
24 select(-`na`) %>%
25 janitor::clean_names()
79 separate(album_details, into = c("album_detail_type", "album_details"), sep = ": ") %>%
80 mutate(album_detail_type = if_else(album_detail_type == "Re-edition", "Re-release", album_detail_type)) %>%
81 pivot_wider(names_from = album_detail_type, values_from = album_details) %>%
82 janitor::clean_names()
test_longer_wider.R (https://github.com/elbersb/tidylog.git) R · 117 lines
37 })
39 test_that("pivot_wider", {
40 expect_message({
41 outlog <- tidylog::pivot_wider(mtcars, names_from = vs, values_from = cyl)
46 expect_silent({
47 outtidyr <- tidyr::pivot_wider(mtcars, names_from = vs, values_from = cyl)
48 })
51 })
53 test_that("pivot_wider: argument order", {
54 expect_message({
55 out_ab <- tidylog::pivot_wider(names_from = vs, values_from = cyl, data = mtcars)
diverging_chart.R (https://github.com/thomas-neitmann/ggcharts.git) R · 212 lines
ff_column_totals.R (https://github.com/ewenharrison/finalfit.git) R · 203 lines
mod_jhu_death_rate.R (https://github.com/JohnCoene/coronavirus.git) R · 105 lines
zzz.R (https://github.com/hadley/dbplyr.git) R · 61 lines
pivot_longer.R (https://github.com/TysonStanley/tidyfast.git) R · 97 lines
reexports.R (https://github.com/rstudio/sparklyr.git) R · 144 lines
7 #' @include tidyr_nest.R
8 #' @include tidyr_pivot_longer.R
9 #' @include tidyr_pivot_wider.R
10 #' @include tidyr_separate.R
11 #' @include tidyr_unite.R
119 #' Pivot wider
120 #'
121 #' See \code{\link[tidyr:pivot_wider]{pivot_wider}} for more details.
122 #'
123 #' @name pivot_wider
124 #' @export
125 #' @importFrom tidyr pivot_wider
126 NULL
fullTable.R (https://github.com/chschoenenberger/covid19_dashboard.git) R · 132 lines
equality-line.R (https://github.com/ikashnitsky/dataviz-mpidr.git) R · 74 lines
test-pivot_wider.R (https://github.com/markfairbanks/tidytable.git) R · 181 lines
1 # tests from tidyr regarding pivot_wider
3 test_that("can pivot all cols to wide", {
4 df <- data.table(label = c("x", "y", "z"), val = 1:3)
5 pivot_df <- pivot_wider.(df, names_from = label, values_from = val)
7 expect_named(pivot_df, c("x", "y", "z"))
11 test_that("non-pivoted cols are preserved", {
12 df <- data.table(a = 1, label = c("x", "y"), val = 1:2)
13 pivot_df <- pivot_wider.(df, names_from = label, values_from = val)
15 expect_named(pivot_df, c("a", "x", "y"))
19 test_that("implicit missings turn into explicit missings", {
20 df <- data.table(a = 1:2, label = c("x", "y"), val = 1:2)
21 pivot_df <- pivot_wider.(df, names_from = label, values_from = val)
23 expect_equal(pivot_df$a, c(1, 2))
ds_github.cssegisanddata.covid19unified.R (https://github.com/covid19datahub/COVID19.git) R · 82 lines
Format_signatures.R (https://github.com/UMCUGenetics/MutationalPatterns.git) R · 191 lines
43 signatures = signatures %>%
44 tidyr::pivot_longer(-sig, names_to = "Type_subtype", values_to = "values") %>%
45 tidyr::pivot_wider(names_from = sig, values_from = values) %>%
46 dplyr::mutate(Type = str_replace(Type_subtype, ".*\\[(.*)\\].*", "\\1"),
47 SubType = str_remove_all(Type_subtype, "\\[|\\]|\\>[A-Z]")) %>%
emerald_soilwater_2015.r (https://github.com/APSIMInitiative/ApsimX.git) R · 136 lines
96 # turn (depth, sw, bd) rows for each layer number into columns so we can compare with simulation results.
98 sw2015_hill_furrow <- data %>% pivot_wider(id_cols = c(year, sowing, hill_furrow, date), names_from = layer_no, values_from = c(depth, sw, bd))
100 # long <- data %>% gather(key = "variable", value = "value", c(depth, sw, bd))
118 # turn (depth, sw, bd) rows for each layer number into columns so we can compare with simulation results.
120 #sw2015 <- data %>% pivot_wider(id_cols = c(year, sowing, date), names_from = layer_no, values_from = c(depth, sw, bd))
121 sw2015 <- data %>% pivot_wider(names_from = layer_no, values_from = c(depth, sw, bd))
129 help("pivot_wider")
130 help("pivot_longer")
genius_url.R (https://github.com/JosiahParry/geniusR.git) R · 136 lines
23 #' @export
24 #' @importFrom rvest session html_nodes html_node html_text
25 #' @importFrom tidyr pivot_wider fill separate replace_na
26 #' @importFrom stringr str_detect str_extract str_replace_all str_trim
27 #' @importFrom tibble tibble
94 str_detect(lyric, "\\[|\\]") ~ "meta",
95 TRUE ~ "lyric")) %>%
96 pivot_wider(names_from = type, values_from = lyric) %>%
98 #spread(key = type, value = lyric)
reexports.R (https://github.com/sparklyr/sparklyr.git) R · 174 lines
broadway-scrape.R (https://github.com/gkaramanis/tidytuesday.git) R · 29 lines
pyramids.R (https://github.com/ikashnitsky/dataviz-mpidr.git) R · 168 lines
test-dt_pivot_wider.R (https://github.com/TysonStanley/tidyfast.git) R · 73 lines
1 # tests from tidyr regarding pivot_wider
3 test_that("can pivot all cols to wide", {
4 df <- data.table(label = c("x", "y", "z"), val = 1:3)
5 pivot_df <- dt_pivot_wider(df, names_from = label, values_from = val)
7 expect_named(pivot_df, c("x", "y", "z"))
12 test_that("non-pivoted cols are preserved", {
13 df <- data.table(a = 1, label = c("x", "y"), val = 1:2)
14 pivot_df <- dt_pivot_wider(df, names_from = label, values_from = val)
16 expect_named(pivot_df, c("a", "x", "y"))
20 test_that("implicit missings turn into explicit missings", {
21 df <- data.table(a = 1:2, label = c("x", "y"), val = 1:2)
22 pivot_df <- dt_pivot_wider(df, names_from = label, values_from = val)
24 expect_equal(pivot_df$a, c(1, 2))
select_helpers.R (https://github.com/TysonStanley/tidyfast.git) R · 54 lines
rowData.R (https://github.com/waldronlab/curatedMetagenomicData.git) R · 61 lines
47 rowDataLong <-
48 purrr::map(taxized, ~ dplyr::select(.x, name, value)) |>
49 purrr::map_dfr(~ tidyr::pivot_wider(.x, values_from = "value")) |>
50 dplyr::select(tidyselect::all_of(rank_names)) |>
51 dplyr::mutate(across(.fns = ~ base::as.character(.x))) |>
55 rowDataNCBI <-
56 purrr::map(taxized, ~ dplyr::select(.x, name, id)) |>
57 purrr::map_dfr(~ tidyr::pivot_wider(.x, values_from = "id")) |>
58 dplyr::select(tidyselect::all_of(rank_names)) |>
59 dplyr::mutate(across(.fns = ~ base::as.integer(.x))) |>
narrabri_actuals.r (https://github.com/APSIMInitiative/ApsimX.git) R · 146 lines
79 plant_2006 <- bind_rows(lai_2006, sites_2006, bolls_2006)
80 plant_2006 <- plant_2006 %>% pivot_wider(names_from = variable, values_from = values)
81 plant_2006 <- plant_2006 %>% mutate(date = dmy("10/10/2006") + days(das))
82 plant_2006 <- plant_2006 %>% mutate(year = 2006) %>% select(year, Treatment, date, das, everything())
100 plant_2007 <- bind_rows(lai_2007, sites_2007, squares_2007, bolls_2007)
101 plant_2007 <- plant_2007 %>% pivot_wider(names_from = variable, values_from = values)
102 plant_2007 <- plant_2007 %>% mutate(date = dmy("15/10/2007") + days(das))
103 plant_2007 <- plant_2007 %>% mutate(year = 2007) %>% select(year, Treatment, date, das, everything())
127 plant_2008 <- bind_rows(lai_2008, sites_2008, squares_2008, bolls_2008, greenbolls_2008, openbolls_2008)
128 plant_2008 <- plant_2008 %>% pivot_wider(names_from = variable, values_from = values)
129 plant_2008 <- plant_2008 %>% mutate(date = dmy("15/10/2008") + days(das))
130 plant_2008 <- plant_2008 %>% mutate(year = 2008) %>% select(year, Treatment, date, das, everything())
0041-basic-word-stats-and-plots.R (https://github.com/benmarwick/saa-meeting-abstracts.git) R · 145 lines
51 group_by(word, year_group) %>%
52 summarise(mean_prop = mean(prop, na.rm = TRUE)) %>%
53 pivot_wider(names_from = year_group,
54 values_from = mean_prop) %>%
55 drop_na() %>%
126 df_tbl_prop_two_groups %>%
127 select(word, prop, year_group) %>%
128 pivot_wider(names_from = year_group,
129 values_from = prop,
130 values_fn = list(prop = mean))
03-tidy-data.R (https://github.com/joanby/tidyverse-data-science.git) R · 148 lines
ks-tidiers.R (https://github.com/tidymodels/broom.git) R · 70 lines
8 #'
9 #' @details Returns a data frame in long format with four columns. Use
10 #' \code{tidyr::pivot_wider(..., names_from = variable, values_from = value)}
11 #' on the output to return to a wide format.
12 #'
26 #'
27 #' td %>%
28 #' pivot_wider(c(obs, estimate),
29 #' names_from = variable,
30 #' values_from = value
test_generate_predictor.R (https://github.com/edunford/tidysynth.git) R · 236 lines
107 x3 = mean(x3)) %>%
108 tidyr::gather(variable,value,-unit) %>%
109 tidyr::pivot_wider(names_from = unit,values_from=value))
132 x3 = mean(x3)) %>%
133 tidyr::gather(variable,value,-unit) %>%
134 tidyr::pivot_wider(names_from = unit,values_from=value))
135 })
207 x3 = mean(x3)) %>%
208 tidyr::gather(variable,value,-unit) %>%
209 tidyr::pivot_wider(names_from = unit,values_from=value))
mod_table_world.R (https://github.com/JohnCoene/coronavirus.git) R · 66 lines
longer_wider.R (https://github.com/elbersb/tidylog.git) R · 41 lines
path_curves.r (git://github.com/ggobi/tourr.git) R · 40 lines
test-tidyr-pivot-wider.R (https://github.com/sparklyr/sparklyr.git) R · 270 lines
8 sdf <- copy_to(sc, tibble::tibble(key = c("x", "y", "z"), val = 1:3))
9 pv <- tidyr::pivot_wider(
10 sdf,
11 names_from = key, values_from = val, names_sort = TRUE
21 sdf <- copy_to(sc, tibble::tibble(a = 1, key = c("x", "y"), val = 1:2))
22 pv <- tidyr::pivot_wider(
23 sdf,
24 names_from = key, values_from = val, names_sort = TRUE
34 sdf <- copy_to(sc, tibble::tibble(a = 1:2, key = c("x", "y"), val = 1:2))
35 pv <- tidyr::pivot_wider(
36 sdf,
37 names_from = key, values_from = val, names_sort = TRUE
path-andrews.r (git://github.com/ggobi/tourr.git) R · 79 lines
test-rvar-.R (https://github.com/jgabry/posterior.git) R · 237 lines
141 d = rvar_from_array(x_array[4,, drop = FALSE])
142 )
143 expect_equal(tidyr::pivot_wider(df, names_from = g, values_from = x), ref)
144 expect_equal(tidyr::pivot_longer(ref, a:d, names_to = "g", values_to = "x"), df)
152 d = c(rvar(NA), NA, NA, df$x[[4]]),
153 )
154 expect_equal(tidyr::pivot_wider(df, names_from = g, values_from = x), ref2)
155 })
test_synthetic_control.R (https://github.com/edunford/tidysynth.git) R · 192 lines
97 expected = controls %>%
98 dplyr::select(time_unit = time,outcome,unit) %>%
99 tidyr::pivot_wider(names_from = unit,values_from = outcome) %>%
100 dplyr::filter(time_unit <= 1995))
107 dplyr::filter(unit!="e") %>%
108 dplyr::select(time_unit = time,outcome,unit) %>%
109 tidyr::pivot_wider(names_from = unit,values_from = outcome) %>%
110 dplyr::filter(time_unit <= 1995))
111 })
177 expected = controls %>%
178 dplyr::select(time_unit = time,outcome,unit) %>%
179 tidyr::pivot_wider(names_from = unit,values_from = outcome) %>%
180 dplyr::filter(time_unit <= 1995))
181 })
transform_seg_table.R (https://github.com/ShixiangWang/sigminer.git) R · 116 lines
2 #'
3 #' @inheritParams get_cn_freq_table
4 #' @inheritParams tidyr::pivot_wider
5 #' @param ref_type annotation data type used for constructing matrix.
6 #'
108 dplyr::select(-c("i.start", "i.end")) %>%
109 na.omit() %>%
110 tidyr::pivot_wider(
111 names_from = "sample", values_from = "segVal",
112 values_fill = values_fill, values_fn = values_fn
dog-friendliness.R (https://github.com/gkaramanis/tidytuesday.git) R · 70 lines
16 child_f <- dog_descriptions %>%
17 count(breed_primary, env_children) %>%
18 pivot_wider(names_from = env_children, names_prefix ="child_", values_from = n) %>%
19 mutate(
20 child_total = child_FALSE + child_TRUE,
24 cat_f <- dog_descriptions %>%
25 count(breed_primary, env_cats) %>%
26 pivot_wider(names_from = env_cats, names_prefix ="cat_", values_from = n) %>%
27 mutate(
28 cat_total = cat_FALSE + cat_TRUE,
utils_table.R (https://github.com/openpharma/visR.git) R · 140 lines
21 dplyr::summarise(N = dplyr::n()) %>%
22 dplyr::mutate(`%` = round(100 * N/sum(N), 3)) %>%
23 tidyr::pivot_wider(names_from = value, values_from = c("N", "%"), names_sep=" ") %>%
24 as.list()
25 list(dat)
90 dplyr::mutate(`n (%)` = paste0(N, " (", format(100 * N/sum(N), digits = 3, trim=TRUE), "%)")) %>%
91 dplyr::select(-N) %>%
92 tidyr::pivot_wider(names_from = value, values_from = c("n (%)"), names_sep=" ") %>%
93 as.list()
94 list(dat)
data-reshaping-lab-key.R (https://github.com/SISBID/Module1.git) R · 55 lines
pivot_wider.R (https://github.com/markfairbanks/tidytable.git) R · 169 lines
Data_Reshaping.R (https://github.com/SISBID/Module1.git) R · 116 lines
mod_table.R (https://github.com/JohnCoene/coronavirus.git) R · 56 lines
pubmed2df.R (https://github.com/massimoaria/bibliometrix.git) R · 77 lines
tidy-exercises.R (https://github.com/ikashnitsky/dataviz-mpidr.git) R · 56 lines
32 # - subset only the year 2004
33 # - transform to wide format using the column "sex" (pivot_wider)
34 # - get rid of the column for both sex
35 # - calculate the sex ratio (males to females)
52 # - subset only both sex
53 # - transform to wide format using the column "year" (pivot_wider)
54 # - calculate the growth of ASDR between 2005 and 2001
55 # Q: in which region the average growth/decrease in ASDR was largest?
Chicago_corr_lm.R (https://github.com/tidymodels/tune.git) R · 92 lines
plot_signature_strand_bias.R (https://github.com/UMCUGenetics/MutationalPatterns.git) R · 112 lines
63 dplyr::mutate(strand = ifelse(strand == "T", "transcribed", "untranscribed")) %>%
64 tidyr::pivot_longer(c(-strand, -type), names_to = "Signature") %>% # Combine signature columns
65 tidyr::pivot_wider(names_from = strand) %>% # Split transcribed/untranscribed column for binom test.
66 dplyr::mutate(
67 observed = as.integer(transcribed),
covmat.R (https://github.com/kingaa/pomp.git) R · 74 lines
friends-table.R (https://github.com/gkaramanis/tidytuesday.git) R · 72 lines
test-pivot-wide.R (https://github.com/cran/tidyr.git) R · 217 lines
3 test_that("can pivot all cols to wide", {
4 df <- tibble(key = c("x", "y", "z"), val = 1:3)
5 pv <- pivot_wider(df, names_from = key, values_from = val)
7 expect_named(pv, c("x", "y", "z"))
11 test_that("non-pivoted cols are preserved", {
12 df <- tibble(a = 1, key = c("x", "y"), val = 1:2)
13 pv <- pivot_wider(df, names_from = key, values_from = val)
15 expect_named(pv, c("a", "x", "y"))
19 test_that("implicit missings turn into explicit missings", {
20 df <- tibble(a = 1:2, key = c("x", "y"), val = 1:2)
21 pv <- pivot_wider(df, names_from = key, values_from = val)
23 expect_equal(pv$a, c(1, 2))