Dear Rex,
Apologies, will post the whole code for you and everyone else to see. I
effectively want to create the csv file for Infosys (INFY.BO) for which I would
like to add more columns after calculations
library(quantmod)
getSymbols("INFY.BO", from="2008-01-01")
data<-INFY.BO
#Have assigned INFY.BO to data
#display the file contents
head(data)
#Now to add the column for high-close
hcdif = Hi(data)-Cl(data)
data$hminus<-hcdif #this works fine
datasmv=filter(Cl(data),rep(1/7,7), sides=1)
data$smv<-datasmv #this also works fine
data[30:40, ] #displays the data file properly
---------------------------------------------------
INFY.BO.Open INFY.BO.High INFY.BO.Low INFY.BO.Close INFY.BO.Volume
[1,] 1560.0 1598.0 1518.00 1558.75 375700
[2,] 1570.0 1600.0 1536.10 1545.40 183100
[3,] 1555.0 1563.0 1501.10 1549.15 200000
[4,] 1560.0 1597.5 1538.00 1547.30 262800
[5,] 1530.1 1579.0 1500.35 1564.75 226200
[6,] 1570.0 1577.0 1543.00 1553.10 66500
[7,] 1565.0 1576.0 1528.00 1556.80 127400
[8,] 1570.0 1588.7 1562.00 1566.05 145700
[9,] 1590.0 1640.0 1575.25 1630.30 366300
[10,] 1619.0 1624.0 1571.00 1580.10 124700
[11,] 1590.0 1620.0 1583.00 1613.45 117700
INFY.BO.Adjusted hminus smv
[1,] 1460.47 39.25 1563.800
[2,] 1447.96 54.60 1557.271
[3,] 1451.48 13.85 1543.914
[4,] 1449.74 50.20 1534.779
[5,] 1466.09 14.25 1542.514
[6,] 1455.18 23.90 1552.829
[7,] 1458.65 19.20 1553.607
[8,] 1467.31 22.65 1554.650
[9,] 1527.51 9.70 1566.779
[10,] 1480.48 43.90 1571.200
[11,] 1511.72 6.55 1580.650
----------------------------------------------------------
write.csv(data,file="infyout.csv") #writes to CSV for future use.
However, if I want to add the lmv, and if I place these two lines of code below
"data[30:40, ] #displays the data file properly", then I face the problem
datalmv=filter(Cl(data),rep(1/21,21), sides=1) #this calculation is fine
data$lmv<-datalmv
Assigning datalmv to data$lmv is where I get the error
Warning message:
In data$lmv <- datalmv : Coercing LHS to a list
This is where I am stuck.
regards
Sean
________________________________
From: rex <[email protected]>
Sent: Thursday, September 27, 2012 2:51 PM
Subject: Re: Coercing LHS to a list
>Houston, we still have a problem....
>It works fine till the four lines,
>hcdif = Hi(data)-Cl(data)
>datasmv=filter(Cl(data),rep(1/7,7), sides=1)
>datalmv=filter(Cl(data),rep(1/21,21), sides=1)
The above work here. A plot of the two shows very similar
behavior.
>data$smv<-datasmv
Why are you doing this? data$smv isn't a valid variable name in the
code you've provided.
>However, for
>
>data$lmv<-datalmv
>Warning message:
>In data$lmv <- datalmv : Coercing LHS to a list
>SMV gets added to the CSV
What CSV? If you download prices using quantmod there's no
CSV involved.
>as another column but once I try to add the LMV, I
>get the above mentioned error
Warnings are not necessarily errors. They mean the operation succeed,
but the result may not be, and probably isn't, what you intended.
>Same if i try and add hcdif using data$HminusC<-hcdif
There's no data$HminusC variable, either. Whatever you may have
read into data with your original read.csv call went away when
you did the assignment data <- FXXX.BO
If you want to add columns to a data.frame you can use cbind(). But
data is an XTS object, not a data.frame, and I don't know if cbind()
works with XTS objects. You could try it and see.
The list protocol calls for complete examples, not code snippets. If
you're doing stuff in your code people on the list can't see, they
can't help.
HTH,
-rex
[[alternative HTML version deleted]]
_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should
go.