Use dplyr (I think) to manipulate a dataset

Sam Cole

I am giving a data set called ChickWeight. This has the weights of chicks over a time period. I need to introduce a new variable that measures the current weight difference compared to day 0.

I first cleaned the data set and took out only the chicks that were recorded for all 12 weigh ins:

Frequency <- dplyr::count(ChickWeight$Chick)
colnames(Frequency)[colnames(Frequency)=="x"] <- "Chick"
a <- inner_join(ChickWeight, Frequency, by='Chick') 
complete <- a[(a$freq == 12),]

This data set is in the library(datasets) of r, called ChickWeight.

27 ϕ 9

You can try:


ChickWeight %>% 
  group_by(Chick) %>%
  filter(any(Time == 21)) %>%
  mutate(wdiff = weight - first(weight))

# A tibble: 540 x 5
# Groups:   Chick [45]
   weight  Time Chick Diet  wdiff
    <dbl> <dbl> <ord> <fct> <dbl>
 1     42     0 1     1         0
 2     51     2 1     1         9
 3     59     4 1     1        17
 4     64     6 1     1        22
 5     76     8 1     1        34
 6     93    10 1     1        51
 7    106    12 1     1        64
 8    125    14 1     1        83
 9    149    16 1     1       107
10    171    18 1     1       129
# ... with 530 more rows

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


How to manipulate paired dataset in R?

How do I use ioctl() to manipulate my kernel module?

Is it essential that I use libraries to manipulate XML?

Boost::Regex Segfault (I think)

How can I filter from a reactive dataset using dplyr?

Why does the C# compiler think I'm trying to use the sbyte overload when using nullable longs?

Why can't I use double colon operator with dplyr when the dataset is in sparklyr?

How can I use gather function to manipulate my data frame?

Use I string to refer to a variable inside dplyr?

How to manipulate paired dataset in R?

How do I write a R function that let me manipulate multiple R variables using dplyr's %>% pipes?

How do I use a double pointer to manipulate an array in C?

How can I use dplyr::filter with "|" operator?

QuickSort not working, think swap is the issue, Disclaimer I must use the quicksort method provided to me

How can I use time in Java to manipulate code?

File Written in Chinese (I think?)

How should i manipulate angularjs resource object for use in the view

Why do we use id in html. I think we can use a class as an id

Xcode error(I think)?

I think MySqli select is not working?

How can I use a Matrix as a dataset on PyBran?

Port forwarding issue (I think)

I think my ssd is bad

Am I missing the obvious ? I think I will have to use ispostback here but not understanding how

How can I manipulate dataframe columns with different values from an external vector (with dplyr)

Use dplyr to group-by dataset and summarize mean and SD (standard deviation)

How can I use dataset with cloneelement?

Merging two Dataset with Dplyr

How can I manipulate JSON data in dart / flutter for use in a listview

TOP Ranking

  1. 1

    What exactly is memory mapped io and port based io

  2. 2

    How i extract text from a model dialog in selenium?

  3. 3 port in URL

  4. 4

    Selenium browsing with headless isn't working?

  5. 5

    change TabView indicator SwiftUI

  6. 6

    python requests How to send data to a website

  7. 7

    Kubernetes pods not starting, running behind a proxy

  8. 8

    Scaffold-DbContext returns System.ArgumentNullException: Parameter name: proposedIdentifier in EFCore 2.0 when trying to pluralize

  9. 9

    Java POI: How to find an Excel cell with a string value and get its position (row) to use that position to find another cell

  10. 10

    Creating interaction sessions based on timestamps in pandas

  11. 11

    Maven annotation processing processor not found

  12. 12

    Missing field when deserializing using Jackson (Polymorphic)

  13. 13

    Spring Data JPA repository methods don't recognize property names with underscores

  14. 14

    Get all Woocommerce products from current product category term Id in a WP_Query

  15. 15

    How to update if key exists - sequelize

  16. 16

    I got message for error_log file "The stream or file ".../laravel.log" could not be opened: failed to open stream: Permission denied"

  17. 17

    Servlet: HTTP Status 404 - Not Found

  18. 18

    Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Moment'

  19. 19

    what is key in CTTelephonyNetworkInfo().serviceSubscriberCellularProviders and CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology

  20. 20

    Laravel(ajax) 404 not found

  21. 21

    Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters