I have 5 lists that need to be the same length as the lists will be combined into a dataframe. One of them may not be the same length as the other 4 so what I currently have is an if statement that checks the length against the length of one of the other lists and then...
1) I create a temporary list using rep( NA, length ) where length is the extra elements I need to add to extend the list
2) I use the concat function c() to combine the list that needs extending with the list with the NAs.
x <- as.numeric( list )
if( length( list ) < length( main ))
{
temp <- rep( NA, length( main ) - length( list ))
list <- c( list, temp )
}
List 1 - NA NA
List 2 - 32 53 45
Merged List - 32 53 45 NA NA
The problem with this is that I then get a ton of NAs introduced by coercion after the dataframe is created.
Is there a better way of handling this? I assume it has to do with the fact that the main list is numeric. I tried doing the same with 0 instead of NA but that failed for some reason. What I use to extend the length does not matter. I just need it to not be a number other than 0.