setdiff 在列表中无故删除元素?

setdiff removes element without reason in a list?

鉴于:

doc1 <- "Hearty Chicken Chorizo, Kale, Bean and Farro Soup"

doc2 <- "Spinach, Ham and Egg Whites Frittata – 2 Points"

doc3 <- "Lentil Tabouli"

doc4 <- "Individual Brussels Sprout & Potato Frittatas"

doc5 <- "Ahi Tuna Stacks with Ginger-Soy Dressing"

doc6 <- "Sagebrush Annie's Ventura County Cabernet Sauvignon & Merlot Ventura County"

doc7 <- "Lentil Chili"

doc8 <- "Slow Cooker Lentil Stew with Sausage"

doc9 <- "Spicy Lentil and Swiss Chard Soup"

doc10 <- "Tofu-Spinach Lasagne"

doc11 <- "Baked Ziti with Spinach"

doc12 <- "Mushroom, Spinach and Cheddar Wraps"

doc13 <- "Jamaican Jerk Pork Roast – Low Carb & Whole 30"

doc14 <- "Tofu & Broccoli Quinoa Stir-Fry"

doc15 <- "Chicken Fajita Stuffed Peppers"

doc16 <- "SketchBook Pinot Noir Wine"

doc17 <- "Chicken and Vegetable Soup"

doc18 <- "Manhattan Crab Chowder"

doc19 <- "Waterbrook Reserve Chardonnay"

doc20 <- "Chinese Beef and Broccoli"

doc21 <- "Easy Crab Curry"

doc22 <- "Waterbrook Reserve Chardonnay"

# Search for all variables starting with doc and search by name of the objects, returning named list:

doc_list <- mget(ls(pattern = "^doc"))

并且:

query <- "Skinny Chicken Rolls"

我想从列表 L:

中排除查询

setdiff(L, query) 但由于某些原因 returns 我 21 元素,因为 query 不存在于 L.

请告诉我这里缺少什么。

出于某种原因,如果您尝试 dput(doc_list),您将只能获得一半的元素。这是怎么回事?

您的输入中有重复的元素。 setdiff returns 唯一元素(因为它查看的是集合)。所以 'query' 没有删除任何东西——你只是得到应该匹配 unique(L) 的输出,因为 "Waterbrook Reserve Chardonnay" 在你的列表中出现了两次。