Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use left_join() by and suffix args instead of renaming columns manually. #632

Open
Aariq opened this issue Aug 15, 2022 · 3 comments
Open

Comments

@Aariq
Copy link

Aariq commented Aug 15, 2022

# in Status table rename like columns
status_noD <- rename(status_noD, dateStat=date,
editedDateStat=editedDate, measuredByStat=measuredBy,
recordedByStat=recordedBy,
samplingProtocolVersionStat=samplingProtocolVersion,
remarksStat=remarks, dataQFStat=dataQF,
publicationDateStat=publicationDate)

Instead of renaming columns manually before left_join()ing, you can do something like this:

left_join(
  status_noD,
  ind_noD,
  by = c(
    "namedLocation",
    "domainID",
    "siteID",
    "plotID",
    "individualID",
    "release"
  ),
  suffix = c("Stat", "")
)

This will add the suffix "Stat" to any duplicate column names not in the vector supplied to by

@cklunch cklunch assigned sokole and unassigned sokole Aug 15, 2022
@cklunch
Copy link
Collaborator

cklunch commented Aug 15, 2022

@Aariq Thanks for the suggestion! For tutorials, it often makes sense to do tasks separately even if it's possible to combine them, so the process and the steps are clearer to the student. I'll leave it up to @kjones13 whether to make this change.

@Aariq
Copy link
Author

Aariq commented Aug 16, 2022

Yeah, I totally get that. I just felt to me like it would make more sense to explain that you want to join by certain columns rather than that you want to avoid certain columns when joining.

@kjones13
Copy link

Hi @Aariq, this is very clean code, and I really I appreciate the suggestion. In this instance, the intent in this step was to be explicit about acknowledging the fieldnames the two data frames have in common and intentionally renaming the fields before joining, as part of the data exploration step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants