# Help Deleting value in a list greater than 10

I am constructing a program where I need a to construct a vector of values. These values are constructed from other vectors. A particular vector M has thousands of values, but I need to delete/create a vector that contains all those values below 10. It should be noted that there is values missing (NA) with in M. I have tried everything I can think of.

Examples of codes I have tried:

1. if (M<10,D==M) , where D is an empty vector

2. if (M<10 || M%in%NA) {D==M}

I have tried others, such as the use of list.append. I am absolutely stuck.

Like this?

``````M <- sample(1:20,size = 20, replace = TRUE)
M
#>   16 16 12  3 13  6  9 19 11  2  7 18  8 20 17  9 10  3  3 19
D <- M[M < 10]
D
#>  3 6 9 2 7 8 9 3 3
``````

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

M < 10 returns 20 TRUE/FALSE values and only the elements where the value is TRUE are kept.

1 Like

Thank You!!!!! I was making that so much harder than it was. Just so I understand the code. What exactly is M[M<10] doing? If I am correct it is selecting all the index's values which are less than 10, correct?

The comparison M < 10 simply returns TRUE and FALSE values. When used as the indexes to subset a vector, TRUE mean "keep" and FALSE means "don't keep". Here is some code that might help explain that. Notice that the M vector here is not the same as in my previous post.

``````M <- sample(1:20,size = 20, replace = TRUE)
M
#>   17 16 18  1 17 10 18 20  8  5  7  7  4 18  1  5 20  4 13 20
M < 10
#>   FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
#>   TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE
Idx <- M < 10
M[Idx]
#>  1 8 5 7 7 4 1 5 4
M[M < 10]
#>  1 8 5 7 7 4 1 5 4
``````

Created on 2020-02-08 by the reprex package (v0.2.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9465495,"math_prob":0.8380243,"size":537,"snap":"2022-27-2022-33","text_gpt3_token_len":136,"char_repetition_ratio":0.14071295,"word_repetition_ratio":0.0,"special_character_ratio":0.26070765,"punctuation_ratio":0.1092437,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97298217,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-05T01:03:18Z\",\"WARC-Record-ID\":\"<urn:uuid:802f35f0-a604-42d0-aa7b-6b245a671aa3>\",\"Content-Length\":\"28070\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:00efea05-48e4-440f-a4c9-efd3e412c371>\",\"WARC-Concurrent-To\":\"<urn:uuid:4f2efb5f-de4f-4ae8-8d30-905035d9ffb6>\",\"WARC-IP-Address\":\"167.99.20.217\",\"WARC-Target-URI\":\"https://community.rstudio.com/t/help-deleting-value-in-a-list-greater-than-10/52113\",\"WARC-Payload-Digest\":\"sha1:RSZDYFFS24UWWFEBQQDZ7QBPOPTPQB3Z\",\"WARC-Block-Digest\":\"sha1:6QKDXKYYQWGK2D6NKBUGXUJVQRWLIYNA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104506762.79_warc_CC-MAIN-20220704232527-20220705022527-00459.warc.gz\"}"}