Relative Content

Tag Archive for rdataframedplyr

Issues getting FSA function ‘Depletion’ to work with dplyr

Without getting into the details of the application, I need to run the FSA::depletion(function) in R on a dataframe where the function needs to run iteratively to find a ‘depletion’ value for X number of rows and then proceed to run the operation on the next X number of rows. A dataframe will look something like this:

combine two dataframes in R by the pathway column when the pathways are differing in number

I have two dataframes, lets say df1 and df2 as pictured below. I want to use R to combine them by adding df2 columns to df1 by pathway column. However, I want the pathway to be repeated as many times as present in the df that has more frequency of the pathway. So for example, HALLMARK_ADIPOGENESIS occurs 6 times in df1 while it occurs 4 times in df2. I want in the combined_df to have that pathway repeated 6 times with the 6 rows having values for all the _B1_7486 columns but only 4 rows having values for the _B1_7534 and the remaining 2 rows to be NAs or blank for the _B1_7534. I have tried using merge and cbind and different iterations but have come up short. Any help would be appreciated.