I want to find the difference between rows based on specific criteria. I managed to do this using dplyr and the mutate function with lag. I have about 10 columns and 500 rows. I am able to find the difference for most rows in columns except for a couple. The problem is that the two of the columns are in factors form and using my code leads to the warning message: in ops.factor not meaningful for factors. To combat this, I tried changing numeric to character.
y <- mutate(df, d_f = df$L - lag(df$L) + n())
x <- as.numeric(as.character(df$z))
This leads to a warning message. Using suppresswarnings(x) leads to all values in the column to become NA by coercion.
How can I change the factors to a different form so that I can find the difference between the rows? The columns causing this problem are in percentages if that makes any difference.
On a side note: I'm new to R and it does seem pretty cool.