I create a dataframe called df and give column names to it. Then I create a new list called test_list. I loop through dataframe(df) and sort them in order.
Now, How do I print or extract only first 5 elements in the list(test_fun)?
df<- data.frame(45,67,78,89,45,65,54,67,87)
colnames(df) <- c("A","B","C","D","E","F","G","H","I")
test_list <- list()
for(i in 1:nrow(df))
{
test_list[[i]] <- colnames(sort(df[i,c(1:9)], decreasing = TRUE))
}
I tried,
test_list[[1]]
#gives output
#[1] "D" "I" "C" "B" "H" "F" "G" "A" "E"
test_list[c(1,2,3,4,5)]
#gives output
#[[1]]
#[1] "D" "I" "C" "B" "H" "F" "G" "A" "E"
#[[2]]
#NULL
#[[3]]
#NULL
#[[4]]
#NULL
#[[5]]
#NULL
But, I need
#output as
#D
#I
#C
#B
#H