Reputation: 551
lets say I have a list in r that contains other lists and I want to remove certain characters (comma in the following example) from elements of each list.
my.list <- list(c("hello , world ", "hello world,,," ),c("123,456", "1,234"))
The following gets the job done
gsub(",", "", my.list[[1]])
gsub(",", "", my.list[[2]])
but how do I do it more efficiently as my actual problem is long? I tried the following but it gives me strange results
lapply(my.list, function(x) gsub(",","",my.list))
any help? thx
Upvotes: 0
Views: 65
Reputation: 49
You might be able to utilize the function filter_element
I would suggest sanitizing your data before combining them into a list. Once the data has been sanitized, then start setting entering them into lists.
You can check out the documentation for filter_element
on page 10 in the following PDF.
https://cran.r-project.org/web/packages/textclean/textclean.pdf
Upvotes: 1