I think it is what I want. The values look OK. I do get a warning. Here is
what you asked for:

> dat=read.csv(file_path, header=F)
Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'y:\ALL
STRATEGIES\INVEST-TRADING\Zacks\RCsvData\VarPortRtns.csv'
> str(dat)
'data.frame':   1 obs. of  251 variables:
 $ V1  : num 0
 $ V2  : num -0.24
 $ V3  : num 0.355
 $ V4  : num -0.211
 $ V5  : num 1.18
 $ V6  : num -0.228
 $ V7  : num 0.748
 $ V8  : num -1.05
 $ V9  : num 0.566
 $ V10 : num -0.184
 $ V11 : num -0.693

...etc....

> dat
  V1         V2        V3       V4      V5         V6        V7
V8        V9        V10        V11        V12        V13       V14
V15         V16       V17       V18         V19        V20
1  0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 -1.049239
0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988 0.5606208
-0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118
        V21       V22       V23       V24       V25       V26
V27        V28       V29        V30        V31       V32        V33
V34        V35       V36        V37        V38       V39
1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237
-0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 -0.07399785
-0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169
          V40      V41        V42        V43       V44        V45
V46        V47        V48         V49       V50      V51       V52
V53        V54       V55        V56        V57        V58
1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 -1.090505
-0.2702305 -0.4381005 -0.06666691 0.1836706 0.728843 0.2219863 -0.7939716
-0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147
         V5

...etc...

Ben

On Thu, Oct 27, 2011 at 1:37 PM, Nordlund, Dan (DSHS/RDA) <
nord...@dshs.wa.gov> wrote:

> > -----Original Message-----
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Ben quant
> > Sent: Thursday, October 27, 2011 12:26 PM
> > To: r-help@r-project.org
> > Subject: Re: [R] preceding X. and X
> >
> > Figured it out. Solution:
> > dat=read.csv(file_path, header=F)
> > > dat
> >   V1         V2        V3       V4      V5         V6        V7
> > V8        V9        V10        V11        V12        V13       V14
> > V15         V16       V17       V18         V19        V20
> > 1  0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 -
> > 1.049239
> > 0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988
> > 0.5606208
> > -0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118
> >         V21       V22       V23       V24       V25       V26
> > V27        V28       V29        V30        V31       V32        V33
> > V34        V35       V36        V37        V38       V39
> > 1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237
> > -0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 -
> > 0.07399785
> > -0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169
> >           V40      V41        V42        V43       V44        V45
> > V46        V47        V48         V49       V50      V51       V52
> > V53        V54       V55        V56        V57        V58
> > 1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 -
> > 1.090505
> > -0.2702305 -0.4381005 -0.06666691 0.1836706 0.728843 0.2219863 -
> > 0.7939716
> > -0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147
> >          V59        V60      V61        V62       V63        V64
> > V65      V66      V67        V68       V69       V70       V71
> > V72        V73       V74       V75        V76        V77
> > 1 -0.1374674 0.05771337 0.615591 -0.2103958 0.3729799 -0.7636618
> > 1.222489
> > 1.175414 1.349652 -0.0653956 0.4461732 0.7385489 0.4267874 -0.4099944
> > -0.4456437 0.1310654 0.5912901 0.03645256 -0.1760742
> >         V78       V79       V80
> >
> > Thanks,
> > Ben
> >
> > On Thu, Oct 27, 2011 at 1:12 PM, Justin Haynes <jto...@gmail.com>
> > wrote:
> >
> > > Id look at the actual csv file.  I assume it has the X there also.
> > > sounds like a good candidate for some data munging tools first before
> > > you bring it into R.  also ?str of the data would be helpful. My
> > first
> > > guess is those are all being read as column names.  Were they data in
> > > the data.frame dat the should be quoted:
> > >
> > > > dat<-c('X0.0','X.0.24','X0.35','X.0.211')
> > > > dat
> > > [1] "X0.0"    "X.0.24"  "X0.35"   "X.0.211"
> > >
> > > versus:
> > >
> > > > names(dat)<-c('col_one','X.0.44',0.65,'last_col')
> > > > dat
> > >  col_one    X.0.44      0.65  last_col
> > >   "X0.0"  "X.0.24"   "X0.35" "X.0.211"
> > >
> > >
> > >
> > > However, if you want to use R to clean it up, I'd use the stringr
> > package.
> > >
> > > > library(stringr)
> > >
> > > > dat<-str_replace(dat,'X.0.','-0.')
> > > > dat
> > > [1] "X0.0"   "-0.24"  "X0.35"  "-0.211"
> > > > dat<-str_replace(dat,'X','')
> > > > dat
> > > [1] "0.0"    "-0.24"  "0.35"   "-0.211"
> > > > dat<-as.numeric(dat)
> > > > dat
> > > [1]  0.000 -0.240  0.350 -0.211
> > > >
> > >
> > > hope that helps,
> > >
> > > Justin
> > >
> > >
> > > On Thu, Oct 27, 2011 at 11:47 AM, Ben quant <ccqu...@gmail.com>
> > wrote:
> > > > Hello,
> > > >
> > > > Why do I get preceding "X." (that is a and X followed by a period)
> > for
> > > > negative numbers and an "X" for positive numbers when I read a csv
> > file?
> > > Am
> > > > I stuck with this? If so, how do I convert it to normal numbers?
> > > >
> > > > dat=read.csv(file_path)
> > > >
> > > >> dat
> > > >  [1] X0.0               X.0.240432350374   X0.355468069625
> > > > X.0.211469972378   X1.1812797415      X.0.227975150826
> > X0.74834842067
>
> Ben,
>
> Are you sure that is what you want?  What is the result of running
>
> str(dat)
>
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to