I have a data frame (data) in R with thousands of rows and 10 columns. 9 of the columns contain factors with several levels.
Here is a small portion of the data frame.
A gr1
10 303.90
11 304.1
12 303.6
13 303.90 obs
14 303.90k
As an example, one factor has a level that is "303.90" and another level that is "303.90 obs". I want to change the "303.90 obs" to "303.90". I am using the following command to edit the names of the level.
data[] = as.data.frame(lapply(data, function(x) {x = gsub("303.90 obs","303.90", fixed = T, x)}))
But this is not changing the level "303.90 obs" to "303.90". It just stays the same. Still this command works for other strings, eg. "303.9" gets changed to "303.90" when I use:
data[] = as.data.frame(lapply(data, function(x) {x = gsub("303.9 obs","303.90", fixed = T, x)}))
Any suggestions to why this might be ?