r - Print only first 5 elements of the list -


i create dataframe called df , give column names it. create new list called test_list. loop through dataframe(df) , sort them in order.

now, how print or extract first 5 elements in 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, need

#output #d #i #c #b #h 

using head

head(test_list[[1]],5) [1] "d" "i" "c" "b" "h" 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -