0

In R:

I tried to make a list of dataframes arrayed by the names of dataframes (p_text_tm_list_1, p_text_tm_list_2, ..., p_text_tm_list_892)

by using loop (for i in 1:892)

but the result of that codes was arrayed by binary (1,10,100,101...) system as you can see in the second captured console screen.

Why was the result arrayed by binary system?

How can I array the dataframe in decimal system?

Thanks for reading.

enter image description here
enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • The last one is `102`, not binary. – Rui Barradas Jun 21 '20 at 08:05
  • 1
    The elements of you list are sorted by the names of your dataframes. The names are sorted aphabetically, so everything with a suffix starting with a `1` precedes everything with a suffix starting with a `2` and so on. To solve your problem, you'll need to be a little more sophisticated in your processing of the data frames. We can help you, but you maximise your chances of a full response by providing a simple, self-contained example. Screenshots don't help. [This post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) may be helpful. – Limey Jun 21 '20 at 08:06
  • Those numbers are not all "binary", they are in the order returned by `mget`. If you see the last ones you will see other numbers. – Rui Barradas Jun 21 '20 at 08:11

1 Answers1

1

Here is a way to solve your problem.
First, create the list p_text_top10_list without resorting to assign. The list is created with its final length in order not to keep extending it,which is ineffective.

p_text_top10_list <- vector("list", length = length(p_text_tm_list))
for(i in seq_along(p_text_tm_list)){
  p_text_top10_list[[i]] <- head(p_text_tm_list[[i]], 10)
}

Another much simpler way is to use lapply.

p_text_top10_list <- lapply(p_text_tm_list, head, 10)

That's it. This one-liner does exactly the same as the previous for loop.

Now assign the names with 3 digits to have them in the proper order.

names(p_text_top10_list) <- sprintf("p_text_top10_list_%03d", seq_along(p_text_top10_list))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66