[R-SIG-Finance] Error: Unexpected symbol in "1M"
Joshua Ulrich
josh.m.ulrich at gmail.com
Mon Feb 25 01:26:02 CET 2013
This has nothing to do with finance, so you should have posted it to
R-help instead.
The answer to your question is found in "An Introduction to R",
section 1.8: R commands, case sensitivity, etc. "... a name must
start with '.' or a letter, and if it starts with '.' the second
character must not be a digit." Technically, you can assign a value
to a name that starts with a number, but you will run into lots of
problems.
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2013: Applied Finance with R | www.RinFinance.com
On Sun, Feb 24, 2013 at 5:48 PM, Wei-han Liu <weihanliu2002 at yahoo.com> wrote:
> Hi R users:
>
> I tried the following coding:
> COMPdata <- read.csv("D:/........./Book1.csv", header=TRUE, sep=",")
> INDEX <- COMPdata[, 1]
> 1M <- COMPdata[, 2]
> 2M <- COMPdata[, 3]
>
> The partial list of original data Book1.csv is listed below:
> INDEX 1M 2M 3M 4M
> 1 0.0001026472 0.0001026472 0.0001427507 0.0001026147
> 2 0.0001026109 0.0001026109 0.0001453323 0.0001029040
> 3 0.0001169544 0.0001169544 0.0001326488 0.0001070135
> 4 0.0001159930 0.0001159930 0.0001362505 0.0001048737
> 5 0.0001212301 0.0001212301 0.0001320264 0.0001139550
> 6 0.0001211852 0.0001211852 0.0001247280 0.0001137742
>
> The dataset read-in looks fine:
>> head(COMPdata)
> INDEX X1M X2M X3M X4M
> 1 1 0.0001026472 0.0001026472 0.0001427507 0.0001026147
> 2 2 0.0001026109 0.0001026109 0.0001453323 0.0001029040
> 3 3 0.0001169544 0.0001169544 0.0001326488 0.0001070135
> 4 4 0.0001159930 0.0001159930 0.0001362505 0.0001048737
> 5 5 0.0001212301 0.0001212301 0.0001320264 0.0001139550
> 6 6 0.0001211852 0.0001211852 0.0001247280 0.0001137742
>
> Nothing wrong with the first column:
>> INDEX <- COMPdata[, 1]
>
> However, it gives me the error message below
>> 1M <- COMPdata[, 2]
> Error: Unexpected symbol in "1M"
>
> So do the other variables 2M, 3M, and 4M.
>
>
> Could some people share advice to solve this problem?
>
> Thanks for your kind attention.
>
> Weihan
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at r-project.org 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.
More information about the R-SIG-Finance
mailing list