1

I've got a list of dataframe my_OHLCV_data and I'm having trouble creating a new column with a list with the correspondent names.

This is what I got:

 print(my_OHLCV_data)
    [[1]]
               Open High Low Close   Volume Adjusted
    2019-03-11 8.61  8.8 5.9  8.54 12245200     8.54

    [[2]]
               Open High  Low Close   Volume Adjusted
    2019-03-08 1.75  2.9 1.43  1.54 21725300     1.54

    [[3]]
               Open High  Low Close   Volume Adjusted
    2019-02-22 2.78 4.54 2.72   3.3 68893400      3.3

    print(symbols_names)
    [1] "TTNP" "AVCO" "CCCL"

This is what I'm looking for:

  print(my_OHLCV_data)
    [[1]]
               Open High Low Close   Volume Adjusted  Symbol
    2019-03-11 8.61  8.8 5.9  8.54 12245200     8.54    TTNP

    [[2]]
               Open High  Low Close   Volume Adjusted  Symbol
    2019-03-08 1.75  2.9 1.43  1.54 21725300     1.54    AVCO

    [[3]]
               Open High  Low Close   Volume Adjusted  Symbol
    2019-02-22 2.78 4.54 2.72   3.3 68893400      3.3    CCCL

This is what I came up with and it wasn't even close:

my_OHLCV_data$name <- symbols_names
print(my_OHLCV_data)
          [[1]]
                     Open High Low Close   Volume Adjusted
          2019-03-11 8.61  8.8 5.9  8.54 12245200     8.54

          [[2]]
                     Open High  Low Close   Volume Adjusted
          2019-03-08 1.75  2.9 1.43  1.54 21725300     1.54

          [[3]]
                     Open High  Low Close   Volume Adjusted
          2019-02-22 2.78 4.54 2.72   3.3 68893400      3.3

          $name 
          [1] "TTNP" "AVCO" "CCCL"

1 Answer 1

2

Probably, Map should do it

Map(cbind, my_OHLCV_data, Symbol = symbols_names)

Or using purrr::map2

purrr::map2(my_OHLCV_data, symbols_names,~cbind(.x, Symbol = .y))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.