Skip to content

Instantly share code, notes, and snippets.

@selva86
Created February 29, 2020 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selva86/02f1f8644c7ae62ba0034d94eb271849 to your computer and use it in GitHub Desktop.
Save selva86/02f1f8644c7ae62ba0034d94eb271849 to your computer and use it in GitHub Desktop.
set.seed(100)
df1 <- data.frame(a=rep(1:3, each=4), b=round(runif(12, 10, 20)))
df2 <- data.frame(a=0:1, c=10:11)
# You have two dataframe df1 and df2 from the code below. df1 and df2 have column a in common.
# The challenge for this video is as follows:
# 1. From df1, remove the rows that are present in df2, based on the common column a.
# 2. Create another dataframe df3 that contains all the rows and columns from both datasets.
# 3. In df2, rename column a as `apple` in df2 and create a new dataframe named 'df4' that
# contains only the common rows in df1 and df2.
# 4. In df1, for each unique value of column a, compute the mean, first, second, last
# and second last value of column 'b' in separate columns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment