Problem removing character - "not an atomic vector"

Hi there!

I have a vector that i took from a different data frame, that looks like this:

vector<- c("1-2-3-4-1-2-3-1-3-4","1-3-3-5-4-3-6-5","1-3-4-3-2-3-5-3-3-2")
str_remove_all(vector,"-")
[1] "1234123134" "13354365"   "1343235332"

I am not sure why, when i try to remove the "-", i have an error that i would not have with this basic example that i showed to you previously. If i would try to do the same thing with the one that i need to change it prints something like this:

str_remove_all(vector,"-")
Warning message:
In stri_replace_all_regex(string, pattern, fix_replacement(replacement),  :
argument is not an atomic vector; coercing

It does creates a vector but its 1x1 and is not what i want, it prints something like this:

[1] "c(\"020000000110000110000000\", \"000000301100000000000010\", 
\"000000000101012000100000\", \"000100000101200000000000\", 
\"000000000101012000101000\", \"001001000102011000100000\", 
\"000000000100000020012000\", \"020100000110000110000000\", 
\"000000000102011000100000\",

The structure of the dataframe's column that i used to create the vector, is something like this:

$ vector: chr [1:92] "0-2-0-0-0-0-0-0-0-1-1-0-0-0-0-1-1-0-0-0-0-0-0-0" "0-0-0-0-0-0-3-0-1-1-0- 
0-0-0-0-0-0-0-0-0-0-0-1-0" "0-0-0-0-0-0-0-0-0-1-0-1-0-1-2-0-0-0-1-0-0-0-0-0" "0-0-0-1-0-0-0-0- 
0-1-0-1-2-0-0-0-0-0-0-0-0-0-0-0" ..

I think it is related to the structure, but i could not figure it out how, I am loosing my mind!

Thank you

It works for me. What's the problem?

library(stringr)

vector <- c("1-2-3-4-1-2-3-1-3-4","1-3-3-5-4-3-6-5","1-3-4-3-2-3-5-3-3-2")

str_remove_all(vector, "-")
#> [1] "1234123134" "13354365"   "1343235332"

Created on 2020-07-07 by the reprex package (v0.3.0)

Thank you for your time, Woodward. I added some information to be clear: I can remove characters from other vectors named like that one, but i can not modify the one that i have to change, and i am not sure why.

Thank you

As you can see, "vector" is the name of a built-in function (that's why it's blue), that might cause you some problems.

Thank you, wood. You saved me!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.