Subtracting a column value which corresponds to a specific value in another column from the every row in that column in R

Advertisements Fish_ID Instance Success First_Success Inst_Diff 1 0 0 0 -2 1 1 0 0 -1 1 2 1 1 0 1 3 0 0 1 1 4 1 0 2 1 5 0 0 3 results %>% group_by(Fish_ID) %>% mutate(Inst_Diff = Instance- Instance[First_Success==1]) I want to create a Inst_Diff column. Using instance number where… Read More Subtracting a column value which corresponds to a specific value in another column from the every row in that column in R

Add a row in data.frame by counting row numbers of another csv with names stored in the data.frame using dplyr

Advertisements I have a data frame of plant Latin names, and another folder GBIF_data that stores the downloaded gbif data in csv named by the Latin names in the data frame, I want to mutate a new column to store how much data has been downloaded from GBIF for each plant Latin name, here is… Read More Add a row in data.frame by counting row numbers of another csv with names stored in the data.frame using dplyr

How to add column with altered ID-names for duplicates within same day

Advertisements I have a data frame with Days, ID, Date collected and a count value (number of hatched eggs) for several samples each day. The ID stems from the replicate (mother) from which the sample (a number of eggs) was taken, so it requires the information from the "Date collected" column in order to distinguish… Read More How to add column with altered ID-names for duplicates within same day

adding a new column to a datframe for 3 condition cases

Advertisements I have a dataframe like this: geneID baseMean log2FoldChange lfcSE stat pvalue padj ENSG00000000003.14 2700.791337 -0.345466785 0.202389477 -1.706940451 0.087833121 0.001 ENSG00000000419.12 1571.143316 -0.348258736 0.150807514 -2.309293001 0.020927328 0.120478416 ENSG00000000457.13 526.2282051 -0.051250213 0.180482116 -0.283962835 0.776438862 0.003 ENSG00000000460.16 1108.138705 -0.078538637 0.167859597 -0.467882913 0.639868323 0.827329552 ENSG00000001036.13 2662.132047 0.121419414 0.175209898 0.692994033 0.488313296 0.728842774 ENSG00000001084.10 1325.447272 0.89 0.154875429 -0.423289781 0.672083849… Read More adding a new column to a datframe for 3 condition cases

Count the number of timestamps in a given vector that fall within an interval in R

Advertisements I want to count the number of events that occur within intervals. I start with a table that has three columns: start dates, end dates, and the interval created by them. table <- tibble( start = c( "2022-08-02", "2022-10-06", "2023-01-11"), end = c("2022-08-04", "2023-02-06", "2023-02-04"), interval = start %–% end ) I also have… Read More Count the number of timestamps in a given vector that fall within an interval in R

In R, how do I make a long dataset that contains all the categories that a row applies to?

Advertisements I have a dataset of students, and I want to create a column that categorizes each student based on their and other students’ data in their "subject" and "grade_letter" column because I eventually want to create a column that says "math_science_A", "science_B", etc. to know how many students got As, Bs, Cs, etc. based… Read More In R, how do I make a long dataset that contains all the categories that a row applies to?

Difference from the mean by column

Advertisements I’ve got this DF: structure(list(Date = structure(c(18605, 18604, 18598, 18597, 18590, 18584, 18583, 18578, 18570, 18569, 18563, 18562, 18557, 18549, 18548, 18542, 18541, 18536, 18534, 18529, 18521, 18520, 18515, 18508, 18500, 18499, 18493, 18492, 18486, 18485, 18479, 18478, 18472, 18471, 18465, 18464, 18458, 18457, 18450, 18445, 18444, 18437, 18436, 18430, 18429, 18424, 18416, 18415,… Read More Difference from the mean by column