Data Loss Using Feature List

I have a simple but strange problem.

index.list is a list containing 118,771 items (integers or numeric). Applying a list of functions, I lose about 500 elements.

Take a look at the following code:

> indices <- unlist(indices.list, use.names = FALSE) > > length(indices.list) [1] 118771 > length(indices) [1] 118248 

How is this possible? I checked if the .list indexes contain any NA. But this is not so:

 > any(is.na(indices.list) == TRUE) [1] FALSE 

data.set.merged is a data frame containing more than 200,000 rows. When I use vector indexes (which apparently have a length of 118,248) to get a subset of the data. Installed, I get a dataframe with 118,771 rows! ?? This is so strange!

 data.set.merged.2 <- data.set.merged[indices, ] > nrow(data.set.2) [1] 118771 

Any ideas what is going on here?

+6
source share
1 answer

Well, for your first riddle, the likely explanation is that some indices.list elements are NULL , which means they will disappear when you use unlist :

 unlist(list(a = 1,b = "test",c = 2,d = NULL, e = 5)) abce "1" "test" "2" "5" 
+10
source

Source: https://habr.com/ru/post/904860/


All Articles