Update column value in XTS object based on date

P.Berg
             SCA-B.ST.Open  SCA-B.ST.High  SCA-B.ST.Low  SCA-B.ST.Close  BOUGHT
 2008-01-14      104.50      105.00         101.50         102.75
 2008-01-15      102.50      102.50         98.25          99.50

I have made an XTS object containing some stock info in R. I have also made a manual list (on paper) of when I entered a position with the stock containing values "B" or "S".

How do I go about to insert "B" or "S" values into the "BOUGHT" column based on the date index the XTS object provides?

rbm

You can simply do (here I assume your xts is called data):

# add col with 'NA' values
data$BOUGHT <- NA
data[as.Date("2008-01-15"),"BOUGHT"] <- "B"
# check/print
data[as.Date("2008-01-15"),"BOUGHT"]

output:

> # add col with 'NA' values
> data$BOUGHT <- NA
> data[as.Date("2008-01-15"),"BOUGHT"] <- "B"
> # check/print
> data[as.Date("2008-01-15"),"BOUGHT"]
           BOUGHT
2008-01-15 "B" 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL Update Value of column Based on DATE

From Dev

UPDATE sql column with value from another column based on a date column

From Dev

Obtain date column from xts object

From Dev

Update a column based on the value of other column

From Dev

ADD a new column into an XTS object

From Dev

Dynamically add column to xts object

From Dev

Add factor column to xts object

From Dev

Update column with previous record based on date

From Dev

Stored procedure to update column based on Min Date

From Dev

How to merge create a column in R that only take one value based on update date

From Dev

How To Update The Date Based On Previous Record Value

From Dev

How To Update The Date Based On Previous Record Value

From Dev

Update a column based on its current value

From Dev

Update first header column based on checkbox value

From Dev

get max date based on column value

From Dev

Incrementally update date field column based on order of a second column

From Dev

Extracting Dates from xts object based on vaule

From Dev

How to subset xts object based upon [is not] condition

From Dev

How to subset xts object based upon [is not] condition

From Dev

Difference between column of a xts zoo object

From Dev

Difference between column of a xts zoo object

From Dev

android update database column based on the current column value

From Dev

Update value in a column based on another column in the same table in MYSQL

From Dev

How to update a Pandas datafrae column based on another column value?

From Dev

Update value in column based on other column values in Spark

From Dev

SQL Server - Select column to update based on another column value

From Dev

Update value in column based on column count in another table with mysql

From Dev

Update column value based on PHP variable which is equal to a column name

From Dev

How can update a column based on the value of another column in SQL?

Related Related

  1. 1

    MySQL Update Value of column Based on DATE

  2. 2

    UPDATE sql column with value from another column based on a date column

  3. 3

    Obtain date column from xts object

  4. 4

    Update a column based on the value of other column

  5. 5

    ADD a new column into an XTS object

  6. 6

    Dynamically add column to xts object

  7. 7

    Add factor column to xts object

  8. 8

    Update column with previous record based on date

  9. 9

    Stored procedure to update column based on Min Date

  10. 10

    How to merge create a column in R that only take one value based on update date

  11. 11

    How To Update The Date Based On Previous Record Value

  12. 12

    How To Update The Date Based On Previous Record Value

  13. 13

    Update a column based on its current value

  14. 14

    Update first header column based on checkbox value

  15. 15

    get max date based on column value

  16. 16

    Incrementally update date field column based on order of a second column

  17. 17

    Extracting Dates from xts object based on vaule

  18. 18

    How to subset xts object based upon [is not] condition

  19. 19

    How to subset xts object based upon [is not] condition

  20. 20

    Difference between column of a xts zoo object

  21. 21

    Difference between column of a xts zoo object

  22. 22

    android update database column based on the current column value

  23. 23

    Update value in a column based on another column in the same table in MYSQL

  24. 24

    How to update a Pandas datafrae column based on another column value?

  25. 25

    Update value in column based on other column values in Spark

  26. 26

    SQL Server - Select column to update based on another column value

  27. 27

    Update value in column based on column count in another table with mysql

  28. 28

    Update column value based on PHP variable which is equal to a column name

  29. 29

    How can update a column based on the value of another column in SQL?

HotTag

Archive