I have a character vector with a name Vector, this is the output:
Vector
[1] "140222" "140207" "0" "140214" "140228" "140322" "140307" "140419" "140517" "140719" "141018" "150117" "160115"
I want to conditionally remove a single element other than the rest, in this case 0.
0
I tried this approach, but it seems to not work:
for (i in 1:length(Vector) { if (nchar(Vector[i]) <=3) {remove(Vector[i])} }
Mistake:
Delete error (Vector [i]): ... must contain names or character strings. "
First of all, you do not need to use a loop for this. This will do what you want:
Vector <- Vector[nchar(Vector) > 3]
If you want to specifically remove "0", you must do this:
Vector <- Vector[Vector != "0"]
, remove Vector, . , remove Vector , . .
remove
R ( - . : ` [`, ` subset`?),
subset(Vector, nchar(Vector) >3)
Source: https://habr.com/ru/post/1525804/More articles:Where can I put my code in Singleton? - c #ghc curses cross compilation not found - ghcMinimum Battery Consumption for Android Microphone Threshold Control - performanceGet the number of messages you like on the FB page using the RestFB API - facebookCreating a path from Bitmap ribs android - javaИсследование/выборка/интерполяция данных VTK с использованием python TVTK или MayaVi - pythonRemove Cookie from Web API 2 - c #angular ngRepeat $ index in name attribute - javascriptError loading pdo_mysql in the built-in php server - phpMVC attribute routing - default controller index with GET and POST - c #All Articles