marker.genes.2 <- list( Gene1 = c(1, 2, 3), Gene2 = c(4, 5, 6, 7), Gene3 = c(8, 9, 10) ) # Find the maximum length among all vectors max_length <- max(sapply(marker.genes.2, length)) # Pad shorter vectors with NA to make them consistent marker.genes.2 <- lapply(marker.genes.2, function(x) { if (length(x) < max_length) { c(x, rep(NA, max_length - length(x))) } else { x } }) # Create a data frame from the corrected list my_data_frame <- data.frame(marker.genes.2) # Display the resulting data frame print(my_data_frame)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter