Relative Content

Tag Archive for rfunction

How to develop Relative Percent Difference Function for dataframe?

I am new to R and so I assume this is something rather simple but I can not find an adequate explanation online or a easy way to go about it. I have a table consisting of rows containing quality control values and original values. I want to create a function that goes through each of the rows, obtains the relative percent difference (RPD) between the Value_QC and Value_Results and then creates a new row on the end with the result. I believe what I need is a function that iterates the RPD formula (attached below) through each row in the column, pulling the Value_QC and Value_Results as the variables. There are also some NAs in the value columns, and I would like to set those to 0 if possible but not sure how to do that either. I know what I want to accomplish, I just don’t have the skills yet in function building in order to develop it. Any help, especially with explanation, would help immensely! Thanks!

My function does not work, the code, separately, does

I try to create a function that checks the data frame to detect the binary vectors (columns) and changes these binary vectors into factors. I have managed to design a code. However, when I tried to wrap it into a function, the function did not work. My question is: what is wrong with my function, and what is missing?

How can I build a function in R that will take a numerical variable as a column name?

I am trying to create a function that will use a number it is passed as a column name for a dataframe. This sounds sort of silly because normally I wouldn’t use numbers as column names, but in this case I’m actually trying to work with a BchronCalibratedDates object produced by the Bchron package, and it is a nested list named after the sample ID, which is usually a number.