3

This question is in relation to another one and its subsequent answers, especially this answer: https://stackoverflow.com/a/14484972/3302795

I apologize if it seems obvious to you but here is my issue. I tried the answers given and it did not always seem to work so I looked for alternatives. As I wrote, it may be due to the data set but here is what I have, I'll try to be as clear as possible but let me know what else you could use:

mydata <- taken from a .csv file

Combination of numbers and text

> dim(mydata)
[1] 214 157

Now I would like to take the first row and convert it into a vector. Here was my attempt from the previous answers:

First, as the original OP tried that didn't work:

> as.vector(mydata[1,])

> is.vector(as.vector(mydata[1,]))
[1] FALSE

No surprise. I then tried:

> unlist(mydata[1,])

> is.vector(unlist(mydata[1,]))
[1] FALSE

This did not yield the same as in the answer and I don't know why, it seems as though it should have worked. So then I tried:

> as.vector(unlist(mydata[1,]))

> is.vector(as.vector(unlist(mydata[1,])))
[1] TRUE

A combination of both that seemed to work. Should this not have worked? Any ideas why the second idea did not work?

To continue to show what I tried from there:

> as.numeric(mydata[1,])

> is.vector(as.numeric(mydata[1,]))
[1] TRUE

This worked to transform into a vector, unfortunately this result does not help in my situation where I would like to keep the text.

*Edit Thx luis, here is more info:

mydata <- read.csv("Test2.csv", sep=";", header=FALSE)

Ugly data taken from a French excel, hence the ";"

> str(mydata)
'data.frame':   214 obs. of  157 variables:
 $ V1  : Factor w/ 214 levels "","American IS® Global Growth & Inc 1",..: 185 82     84 80 83 85 81 2 4 6 ...
 $ V2  : Factor w/ 7 levels "","200","Australian ",..: 4 7 7 7 7 7 7 7 7 7 ...
 $ V3  : Factor w/ 13 levels "","10","6430",..: 13 1 1 1 1 1 1 1 1 1 ...
 $ V4  : Factor w/ 19 levels "","16","AU60BGL01098",..: 6 1 1 1 1 1 1 9 13 12 ...
 $ V5  : Factor w/ 4 levels "","200","Eq",..: 4 3 3 3 3 3 3 3 3 3 ...
 $ V6  : Factor w/ 4 levels "","200","Global Cat",..: 3 4 4 4 4 4 4 4 4 4 ...
 $ V7  : Factor w/ 10 levels "","200","Australia World - ",..: 6 10 10     10 10 10 10 7 7 7 ...
 $ V8  : Factor w/ 6 levels "","188","Institutional Category",..: 3 4 4 4 6 6 6 5 4 6     ...
 $ V9  : Factor w/ 4 levels "","1","Global Eq - Currency ",..: 4 1 1 1 1 1 1 1 1 1 ...
 $ V10 : Factor w/ 9 levels "","1","189","2",..: 9 7 7 7 5 5 5 6 7 5 ...
 $ V11 : Factor w/ 4 levels "","188","International Equity",..: 4 3 3 3 3 3 3 3 3 3 ...
 $ V12 : Factor w/ 7 levels "","200","Australia",..: 4 7 7 7 7 7 7 7 7 7 ...
 $ V13 : Factor w/ 6 levels "","200","Legal Structure",..: 3 4 4 4 4 4 4 4 4 4 ...
 $ V14 : Factor w/ 7 levels "","200","Style Box (Long)",..: 3 5 5 5 7 7 7 4 5 7     ...
 $ V15 : Factor w/ 3 levels "","0","Inc Style Box (Long)": 3 1 1 1 1 1 1 1 1 1     ...
 $ V16 : Factor w/ 17 levels "","200","American Variable",..: 9 3 3 3 3 3 3 3 3 3 ...
 $ V17 : Factor w/ 17 levels "","200","American Variable",..: 5 3 3 3 3 3 3 3 3 3 ...
 $ V18 : Factor w/ 70 levels "","1986-07-23",..: 70 36 36 20 36 36 20 53 4 6 ...
 $ V19 : Factor w/ 12 levels "","192",";;",..: 9 11 11 11 10 10     10 4 11 10 ...
 $ V20 : Factor w/ 12 levels "","[1986-07-23--1994-03-08] J. ;[1994-03-08--1997-03-01]   ;[1997-04-01--2000-12-29] ;[2003-11-"| __truncated__,..: 12 4 4 4 5 5 5 7 4 5 ...
 $ V21 : Factor w/ 8 levels "","188","[$0 - None];[$0 - None];",..: 6 8 8 8 7 7 7 4 8 7     ...
 $ V22 : Factor w/ 15 levels "","1,25","1,67",..: 15 4 4 4 6 6 6 14 4 6 ...
 $ V23 : Factor w/ 15 levels "","1 089,16",..: 15 9 9 9 13 13 13 12 9 13 ...
 $ V24 : Factor w/ 8 levels "","192","ACWI NR USD",..: 8 3 3 3 4 4 4 3 3 4 ...
 $ V25 : Factor w/ 7 levels "","189","",..: 5 7 7 7 4 4 4 7 7 4 ...
 $ V26 : Factor w/ 6 levels "","189","1969-12-31",..: 6 5 5 5 4 4 4 5 5 4 ...
 $ V27 : Factor w/ 10 levels "","188","2002-06-30",..: 10 1 1 1 1 1 1 7 7 7 ...
 $ V28 : Factor w/ 199 levels "","1 172 094",..: 199 1 1 1 1 1 1 55 6 4 ...
 $ V29 : Factor w/ 12 levels "","1999-06-30",..: 12 2 4 4 2 4 4 9 9 9 ...
 $ V30 : Factor w/ 126 levels "","1 033 582 064",..: 126 99 96 9 99 96 9 25 94 87 ...
 $ V31 : Factor w/ 5 levels "","200","Holding of an Investment",..: 3 5 5 5 5 5 5 5 5 5 ...
 $ V32 : Factor w/ 5 levels "","200","No",..: 4 3 3 3 3 3 3 5 5 5 ...
 $ V33 : Factor w/ 5 levels "","12","Acc",..: 4 1 1 1 1 1 1 1 1 1 ...
 $ V34 : Factor w/ 4 levels "","12 Mo Yield Date",..: 2 1 1 1 1 1 1 3 3 3 ...
 $ V35 : Factor w/ 22 levels "","0,00","0,02",..: 15 1 1 1 1 1 1 21 13 9 ...
 $ V36 : Factor w/ 6 levels "","200","2014-01-31",..: 6 5 5 5 5 5 5 5 5 5 ...
 $ V37 : Factor w/ 6 levels "","195","2014-04-30",..: 6 3 3 3 3 3 3 5 5 5 ...
 [list output truncated]

*EDIT My first row, truncated:

> mydata[1,]
V1            V2     V3   V4                          V5              V6                   V7                                 V8
1 Name Base Currency Ticker ISIN Global Broad Category Group Global Category Morningstar Category Site Institutional Category

I'm sorry I would like to point out that the method works with header=TRUE

However, I chose Header=FALSE because it's the first row, the Header that I want as a vector.

Using the given answers

> as.character(mydata[1,])
[1] "82"  "6"   "1"   "1"   "3"   "3"   "9"   "3"   "1"   "5"   "3"   "6"   "3"   "4"       "NA"  "3"   "3"   "36"  "10"  "4"   "7"   "4"   "9"   "3"   "6"  
[26] "5"   "1"   "1"   "2"   "99"  "4"   "3"   "1"   "1"   "1"   "5"   "3"   "49"  "1"   "18"  "76"  "64"  "89"  "81"  "4"   "7"   "1"   "1"   "7"   "6"  
[51] "7"   "4"   "7"   "7"   "NA"  "NA"  "83"  "176" "7"   "NA"  "1"   "6"   "4"   "4"   "3"   "3"   "NA"  "NA"  "1"   "29"  "4"   "28"  "46"  "37"  "3"  
[76] "5"   "12"  "32"  "32"  "7"   "3"   "18"  "5"   "7"   "47"  "31"  "18"  "6"   "4"   "49"  "6"   "34"  "63"  "21"  "35"  "38"  "22"  "16"  "4"   "65" 
[101] "30"  "35"  "21"  "48"  "30"  "28"  "29"  "36"  "13"  "27"  "19"  "53"  "34"  "21"  "47"  "23"  "49"  "49"  "57"  "28"  "55"  "33"  "8"   "36"  "43" 
[126] "43"  "60"  "16"  "16"  "46"  "38"  "46"  "15"  "40"  "52"  "49"  "23"  "23"  "43"  "60"  "36"  "22"  "4"   "19"  "45"  "24"  "11"  "48"  "32"  "63" 
[151] "38"  "54"  "45"  "46"  "46"  "12"  "2" 

However, when I keep header=FALSE

> as.vector(unlist(mydata[1,]))
[1] "Name"                                        "Base Currency"                               "Ticker" 
[4] "ISIN"  

etc.

*EDIT

2 lines of .csv file (I hope this is paste-able):

Name    Base Currency   Ticker  ISIN    Global Broad Category Group Global Category Morningstar Category    Morningstar Institutional Category  Global Investment Fund Sector (GIFS)    Morningstar Rating Overall  US Category Group   Domicile    Fund Legal Structure      Style Box (Long)  Fixed Inc Style Box (Long)  Firm Name   Branding Name   Inception Date  Manager Name    Manager History Manager Tenure (Longest)    Manager Tenure (Average)    Primary Prospectus Benchmark    Primary Prospectus Benchmark Id Primary Prospectus Benchmark Inception Date Net Assets Date Net Assets - Share Class Base Currency  Fund Size Date  Fund Size Base Currency Holding of an Investment    Oldest Share Class  Distribution Status 12 Mo Yield Date    12 Mo Yield Portfolio Date  Return Date (Daily) NAV (Daily) Base Currency   Total Ret 1 Day (Daily) Base Currency   Total Ret YTD (Daily) Base Currency Total Ret 1 Yr (Daily) Base Currency    Total Ret Annlzd 2 Yr (Daily) Base Currency Total Ret Annlzd 3 Yr (Daily) Base Currency Total Ret Annlzd 5 Yr (Daily) Base Currency Management Fee  Annual Report Net Expense Ratio Annual Report Ongoing Charge    Annual Report Ongoing Charge Date   Annual Report Gross Expense Ratio   Prospectus Net Expense Ratio    Prospectus Gross Expense Ratio  Prospectus Objective    Turnover Ratio %    Share Class Type    RRSP    RESP    SecId   PerformanceId   FundId  CUSIP   Analysis Date   Investment Type Performance Data Ready  Price Data Ready    Operations Data Ready   Portfolio Data Ready    Note Effective Date Related Notes   Share Split Monthly Return 2007-01 Base Currency    Monthly Return 2007-02 Base Currency    Monthly Return 2007-03 Base Currency    Monthly Return 2007-04 Base Currency    Monthly Return 2007-05 Base Currency    Monthly Return 2007-06 Base Currency    Monthly Return 2007-07 Base Currency    Monthly Return 2007-08 Base Currency    Monthly Return 2007-09 Base Currency    Monthly Return 2007-10 Base Currency    Monthly Return 2007-11 Base Currency    Monthly Return 2007-12 Base Currency    Monthly Return 2008-01 Base Currency    Monthly Return 2008-02 Base Currency    Monthly Return 2008-03 Base Currency    Monthly Return 2008-04 Base Currency    Monthly Return 2008-05 Base Currency    Monthly Return 2008-06 Base Currency    Monthly Return 2008-07 Base Currency    Monthly Return 2008-08 Base Currency    Monthly Return 2008-09 Base Currency    Monthly Return 2008-10 Base Currency    Monthly Return 2008-11 Base Currency    Monthly Return 2008-12 Base Currency    Monthly Return 2009-01 Base Currency    Monthly Return 2009-02 Base Currency    Monthly Return 2009-03 Base Currency    Monthly Return 2009-04 Base Currency    Monthly Return 2009-05 Base Currency    Monthly Return 2009-06 Base Currency    Monthly Return 2009-07 Base Currency    Monthly Return 2009-08 Base Currency    Monthly Return 2009-09 Base Currency    Monthly Return 2009-10 Base Currency    Monthly Return 2009-11 Base Currency    Monthly Return 2009-12 Base Currency    Monthly Return 2010-01 Base Currency    Monthly Return 2010-02 Base Currency    Monthly Return 2010-03 Base Currency    Monthly Return 2010-04 Base Currency    Monthly Return 2010-05 Base Currency    Monthly Return 2010-06 Base Currency    Monthly Return 2010-07 Base Currency    Monthly Return 2010-08 Base Currency    Monthly Return 2010-09 Base Currency    Monthly Return 2010-10 Base Currency    Monthly Return 2010-11 Base Currency    Monthly Return 2010-12 Base Currency    Monthly Return 2011-01 Base Currency    Monthly Return 2011-02 Base Currency    Monthly Return 2011-03 Base Currency    Monthly Return 2011-04 Base Currency    Monthly Return 2011-05 Base Currency    Monthly Return 2011-06 Base Currency    Monthly Return 2011-07 Base Currency    Monthly Return 2011-08 Base Currency    Monthly Return 2011-09 Base Currency    Monthly Return 2011-10 Base Currency    Monthly Return 2011-11 Base Currency    Monthly Return 2011-12 Base Currency    Monthly Return 2012-01 Base Currency    Monthly Return 2012-02 Base Currency    Monthly Return 2012-03 Base Currency    Monthly Return 2012-04 Base Currency    Monthly Return 2012-05 Base Currency    Monthly Return 2012-06 Base Currency    Monthly Return 2012-07 Base Currency    Monthly Return 2012-08 Base Currency    Monthly Return 2012-09 Base Currency    Monthly Return 2012-10 Base Currency    Monthly Return 2012-11 Base Currency    Monthly Return 2012-12 Base Currency    Monthly Return 2013-01 Base Currency    Monthly Return 2013-02 Base Currency    Monthly Return 2013-03 Base Currency    Monthly Return 2013-04 Base Currency    Monthly Return 2013-05 Base Currency    Monthly Return 2013-06 Base Currency    Monthly Return 2013-07 Base Currency    Monthly Return 2013-08 Base Currency    Monthly Return 2013-09 Base Currency    Monthly Return 2013-10 Base Currency    Monthly Return 2013-11 Base Currency    Monthly Return 2013-12 Base Currency    Monthly Return 2014-01 Base Currency    Monthly Return 2014-02 Base Currency    Monthly Return 2014-03 Base Currency    Monthly Return 2014-04 Base Currency
x   US Dollar               Global      US VL Sub World Stock   World Large Growth      5   International   United States   Open Ended Investment Company   Large Growth        American Variable   American Variable   2003-08-29  x   [1997-04-30--2005-04-27] Donald D. O'Neal;[1997-04-30--2012-09-01] Robert W. Lovelace;[1997-04-30--2003-04-30] Martial Chaillet;[2002-12-31--] Steven T. Watson;[2013-05-01--] Jonathan Knowles;[1998-04-30--2010-04-30] Nicholas J. Grace;[2004-12-31--2013-05-01] Paul A. White;[2009-12-31--2014-05-01] Martin Jacobs;[2012-12-31--] Isabelle de Wismes; 11,42   4,56    MSCI ACWI NR USD    XIUSA04EXL  1998-12-31          1999-06-30  550 871 257 Yes No              2014-03-31  2014-04-30  2,38        -2,01   16,22   16,77   9,07    16,77   0,52    0,8         0,8 0,8 0,8 World Stock 39  Other           VAUSA04BBR  0P0000FPYS  FSUSA00CFF          VL Subaccount   Yes Yes Yes Yes             1,16    -0,21   1,66    4,27    2,97    -0,08   -1,11   -0,21   5,33    4,87    -3,89   -0,43   -5,88   -1,19   -1,25   4,53    1,58    -7,44   -2,6    -2,62   -9,88   -19,01  -6,67   5,64    -7,42   -6,15   7,46    10,88   10,3    -0,16   9,7 3,41    5,37    -1,96   4,44    1,98    -4,67   0,91    6,08    -0,75   -9,37   -2,34   8,5 -3,81   10,29   4,14    -2,68   6,86    0,7 3,61    0,36    4,05    -1,92   -1,61   -2,58   -8,25   -9,29   9,97    -1,4    -1,41   6,9 4,95    1,76    -0,32   -8,66   4,8 1,76    2,15    2,61    0,13    2,72    2,55    3,88    -0,08   2,14    2,74    0,74    -2,06   5,69    -2,45   6,8 3,22    2,94    2,73    -4,38   5,42    -1,89   -0,91

*Second attempt

Name;Base Currency;Ticker;ISIN;Global Broad Category Group;Global Category;Morningstar Category;Morningstar Institutional Category;Global Investment Fund Sector (GIFS);Morningstar Rating Overall;US Category Group;Domicile;Fund Legal Structure; Style Box (Long);Fixed Inc Style Box (Long);Firm Name;Branding Name;Inception Date;Manager Name;Manager History;Manager Tenure (Longest);Manager Tenure (Average);Primary Prospectus Benchmark;Primary Prospectus Benchmark Id;Primary Prospectus Benchmark Inception Date;Net Assets Date;Net Assets - Share Class Base Currency;Fund Size Date;Fund Size Base Currency;Holding of an Investment;Oldest Share Class;Distribution Status;12 Mo Yield Date;12 Mo Yield;Portfolio Date;Return Date (Daily);NAV (Daily) Base Currency;Total Ret 1 Day (Daily) Base Currency;Total Ret YTD (Daily) Base Currency;Total Ret 1 Yr (Daily) Base Currency;Total Ret Annlzd 2 Yr (Daily) Base Currency;Total Ret Annlzd 3 Yr (Daily) Base Currency;Total Ret Annlzd 5 Yr (Daily) Base Currency;Management Fee;Annual Report Net Expense Ratio;Annual Report Ongoing Charge;Annual Report Ongoing Charge Date;Annual Report Gross Expense Ratio;Prospectus Net Expense Ratio;Prospectus Gross Expense Ratio;Prospectus Objective;Turnover Ratio %;Share Class Type;RRSP;RESP;SecId;PerformanceId;FundId;CUSIP;Analysis Date;Investment Type;Performance Data Ready;Price Data Ready;Operations Data Ready;Portfolio Data Ready;Note Effective Date;Related Notes;Share Split;Monthly Return 2007-01 Base Currency;Monthly Return 2007-02 Base Currency;Monthly Return 2007-03 Base Currency;Monthly Return 2007-04 Base Currency;Monthly Return 2007-05 Base Currency;Monthly Return 2007-06 Base Currency;Monthly Return 2007-07 Base Currency;Monthly Return 2007-08 Base Currency;Monthly Return 2007-09 Base Currency;Monthly Return 2007-10 Base Currency;Monthly Return 2007-11 Base Currency;Monthly Return 2007-12 Base Currency;Monthly Return 2008-01 Base Currency;Monthly Return 2008-02 Base Currency;Monthly Return 2008-03 Base Currency;Monthly Return 2008-04 Base Currency;Monthly Return 2008-05 Base Currency;Monthly Return 2008-06 Base Currency;Monthly Return 2008-07 Base Currency;Monthly Return 2008-08 Base Currency;Monthly Return 2008-09 Base Currency;Monthly Return 2008-10 Base Currency;Monthly Return 2008-11 Base Currency;Monthly Return 2008-12 Base Currency;Monthly Return 2009-01 Base Currency;Monthly Return 2009-02 Base Currency;Monthly Return 2009-03 Base Currency;Monthly Return 2009-04 Base Currency;Monthly Return 2009-05 Base Currency;Monthly Return 2009-06 Base Currency;Monthly Return 2009-07 Base Currency;Monthly Return 2009-08 Base Currency;Monthly Return 2009-09 Base Currency;Monthly Return 2009-10 Base Currency;Monthly Return 2009-11 Base Currency;Monthly Return 2009-12 Base Currency;Monthly Return 2010-01 Base Currency;Monthly Return 2010-02 Base Currency;Monthly Return 2010-03 Base Currency;Monthly Return 2010-04 Base Currency;Monthly Return 2010-05 Base Currency;Monthly Return 2010-06 Base Currency;Monthly Return 2010-07 Base Currency;Monthly Return 2010-08 Base Currency;Monthly Return 2010-09 Base Currency;Monthly Return 2010-10 Base Currency;Monthly Return 2010-11 Base Currency;Monthly Return 2010-12 Base Currency;Monthly Return 2011-01 Base Currency;Monthly Return 2011-02 Base Currency;Monthly Return 2011-03 Base Currency;Monthly Return 2011-04 Base Currency;Monthly Return 2011-05 Base Currency;Monthly Return 2011-06 Base Currency;Monthly Return 2011-07 Base Currency;Monthly Return 2011-08 Base Currency;Monthly Return 2011-09 Base Currency;Monthly Return 2011-10 Base Currency;Monthly Return 2011-11 Base Currency;Monthly Return 2011-12 Base Currency;Monthly Return 2012-01 Base Currency;Monthly Return 2012-02 Base Currency;Monthly Return 2012-03 Base Currency;Monthly Return 2012-04 Base Currency;Monthly Return 2012-05 Base Currency;Monthly Return 2012-06 Base Currency;Monthly Return 2012-07 Base Currency;Monthly Return 2012-08 Base Currency;Monthly Return 2012-09 Base Currency;Monthly Return 2012-10 Base Currency;Monthly Return 2012-11 Base Currency;Monthly Return 2012-12 Base Currency;Monthly Return 2013-01 Base Currency;Monthly Return 2013-02 Base Currency;Monthly Return 2013-03 Base Currency;Monthly Return 2013-04 Base Currency;Monthly Return 2013-05 Base Currency;Monthly Return 2013-06 Base Currency;Monthly Return 2013-07 Base Currency;Monthly Return 2013-08 Base Currency;Monthly Return 2013-09 Base Currency;Monthly Return 2013-10 Base Currency;Monthly Return 2013-11 Base Currency;Monthly Return 2013-12 Base Currency;Monthly Return 2014-01 Base Currency;Monthly Return 2014-02 Base Currency;Monthly Return 2014-03 Base Currency;Monthly Return 2014-04 Base Currency x;US Dollar;x;Global ;US VL Sub World Stock;World Large Growth;5;International ;United States;Open Ended Investment Company;Large Growth;American Variable;American Variable;2003-08-29;x;"[1997-04-30--2005-04-27] Donald D. O'Neal;[1997-04-30--2012-09-01] Robert W. Lovelace;[1997-04-30--2003-04-30] Martial Chaillet;[2002-12-31--] Steven T. Watson;[2013-05-01--] Jonathan Knowles;[1998-04-30--2010-04-30] Nicholas J. Grace;[2004-12-31--2013-05-01] Paul A. White;[2009-12-31--2014-05-01] Martin Jacobs;[2012-12-31--] Isabelle de Wismes;";11,42;4,56;MSCI ACWI NR USD;XIUSA04EXL;1998-12-31;;;1999-06-30;550 871 257;Yes;No;;;;2014-03-31;2014-04-30;2,38;;-2,01;16,22;16,77;9,07;16,77;0,52;0,8;;;0,8;0,8;0,8;World Stock;39;Other;;;VAUSA04BBR;0P0000FPYS;FSUSA00CFF;;;VL Subaccount;Yes;Yes;Yes;Yes;;;;1,16;-0,21;1,66;4,27;2,97;-0,08;-1,11;-0,21;5,33;4,87;-3,89;-0,43;-5,88;-1,19;-1,25;4,53;1,58;-7,44;-2,6;-2,62;-9,88;-19,01;-6,67;5,64;-7,42;-6,15;7,46;10,88;10,3;-0,16;9,7;3,41;5,37;-1,96;4,44;1,98;-4,67;0,91;6,08;-0,75;-9,37;-2,34;8,5;-3,81;10,29;4,14;-2,68;6,86;0,7;3,61;0,36;4,05;-1,92;-1,61;-2,58;-8,25;-9,29;9,97;-1,4;-1,41;6,9;4,95;1,76;-0,32;-8,66;4,8;1,76;2,15;2,61;0,13;2,72;2,55;3,88;-0,08;2,14;2,74;0,74;-2,06;5,69;-2,45;6,8;3,22;2,94;2,73;-4,38;5,42;-1,89;-0,91

*Better Name;Base Currency;Ticker;ISIN;Global Broad Category Group;Global Category;Morningstar Category;Morningstar Institutional Category;Global Investment Fund Sector (GIFS);Morningstar Rating Overall;US Category Group;Domicile;Fund Legal Structure;Equity Style Box (Long);Fixed Inc Style Box (Long);Firm Name;Branding Name;Inception Date;Manager Name;Manager History;Manager Ownership Level;Manager Tenure (Longest);Manager Tenure (Average);Primary Prospectus Benchmark;Primary Prospectus Benchmark Id;Primary Prospectus Benchmark Inception Date;Net Assets Date;Net Assets - Share Class Base Currency;Fund Size Date;Fund Size Base Currency;Holding of an Investment;Oldest Share Class;Distribution Status;12 Mo Yield Date;12 Mo Yield;Portfolio Date;Return Date (Daily);NAV (Daily) Base Currency;Total Ret 1 Day (Daily) Base Currency;Total Ret YTD (Daily) Base Currency;Total Ret 1 Yr (Daily) Base Currency;Total Ret Annlzd 2 Yr (Daily) Base Currency;Total Ret Annlzd 3 Yr (Daily) Base Currency;Total Ret Annlzd 5 Yr (Daily) Base Currency;Management Fee;Annual Report Net Expense Ratio;Annual Report Ongoing Charge;Annual Report Ongoing Charge Date;Annual Report Gross Expense Ratio;Prospectus Net Expense Ratio;Prospectus Gross Expense Ratio;Prospectus Objective;Turnover Ratio %;Share Class Type;RRSP;RESP;SecId;PerformanceId;FundId;CUSIP;Analysis Date;Investment Type;Performance Data Ready;Price Data Ready;Operations Data Ready;Portfolio Data Ready;Note Effective Date;Related Notes;Share Split;Monthly Return 2007-01 Base Currency;Monthly Return 2007-02 Base Currency;Monthly Return 2007-03 Base Currency;Monthly Return 2007-04 Base Currency;Monthly Return 2007-05 Base Currency;Monthly Return 2007-06 Base Currency;Monthly Return 2007-07 Base Currency;Monthly Return 2007-08 Base Currency;Monthly Return 2007-09 Base Currency;Monthly Return 2007-10 Base Currency;Monthly Return 2007-11 Base Currency;Monthly Return 2007-12 Base Currency;Monthly Return 2008-01 Base Currency;Monthly Return 2008-02 Base Currency;Monthly Return 2008-03 Base Currency;Monthly Return 2008-04 Base Currency;Monthly Return 2008-05 Base Currency;Monthly Return 2008-06 Base Currency;Monthly Return 2008-07 Base Currency;Monthly Return 2008-08 Base Currency;Monthly Return 2008-09 Base Currency;Monthly Return 2008-10 Base Currency;Monthly Return 2008-11 Base Currency;Monthly Return 2008-12 Base Currency;Monthly Return 2009-01 Base Currency;Monthly Return 2009-02 Base Currency;Monthly Return 2009-03 Base Currency;Monthly Return 2009-04 Base Currency;Monthly Return 2009-05 Base Currency;Monthly Return 2009-06 Base Currency;Monthly Return 2009-07 Base Currency;Monthly Return 2009-08 Base Currency;Monthly Return 2009-09 Base Currency;Monthly Return 2009-10 Base Currency;Monthly Return 2009-11 Base Currency;Monthly Return 2009-12 Base Currency;Monthly Return 2010-01 Base Currency;Monthly Return 2010-02 Base Currency;Monthly Return 2010-03 Base Currency;Monthly Return 2010-04 Base Currency;Monthly Return 2010-05 Base Currency;Monthly Return 2010-06 Base Currency;Monthly Return 2010-07 Base Currency;Monthly Return 2010-08 Base Currency;Monthly Return 2010-09 Base Currency;Monthly Return 2010-10 Base Currency;Monthly Return 2010-11 Base Currency;Monthly Return 2010-12 Base Currency;Monthly Return 2011-01 Base Currency;Monthly Return 2011-02 Base Currency;Monthly Return 2011-03 Base Currency;Monthly Return 2011-04 Base Currency;Monthly Return 2011-05 Base Currency;Monthly Return 2011-06 Base Currency;Monthly Return 2011-07 Base Currency;Monthly Return 2011-08 Base Currency;Monthly Return 2011-09 Base Currency;Monthly Return 2011-10 Base Currency;Monthly Return 2011-11 Base Currency;Monthly Return 2011-12 Base Currency;Monthly Return 2012-01 Base Currency;Monthly Return 2012-02 Base Currency;Monthly Return 2012-03 Base Currency;Monthly Return 2012-04 Base Currency;Monthly Return 2012-05 Base Currency;Monthly Return 2012-06 Base Currency;Monthly Return 2012-07 Base Currency;Monthly Return 2012-08 Base Currency;Monthly Return 2012-09 Base Currency;Monthly Return 2012-10 Base Currency;Monthly Return 2012-11 Base Currency;Monthly Return 2012-12 Base Currency;Monthly Return 2013-01 Base Currency;Monthly Return 2013-02 Base Currency;Monthly Return 2013-03 Base Currency;Monthly Return 2013-04 Base Currency;Monthly Return 2013-05 Base Currency;Monthly Return 2013-06 Base Currency;Monthly Return 2013-07 Base Currency;Monthly Return 2013-08 Base Currency;Monthly Return 2013-09 Base Currency;Monthly Return 2013-10 Base Currency;Monthly Return 2013-11 Base Currency;Monthly Return 2013-12 Base Currency;Monthly Return 2014-01 Base Currency;Monthly Return 2014-02 Base Currency;Monthly Return 2014-03 Base Currency;Monthly Return 2014-04 Base Currency Hart Sg Ar-American Funds IS Global Growth 2;US Dollar;;;Equity;Global Equity;US VL Sub World Stock;World Large Growth;;5;International Equity;United States;Open Ended Investment Company;Large Growth;;American Variable;American Variable;2003-08-29;"Steven T. Watson;Isabelle de Wismes;Jonathan Knowles;";"[1997-04-30--2005-04-27] Donald D. O'Neal;[1997-04-30--2012-09-01] Robert W. Lovelace;[1997-04-30--2003-04-30] Martial Chaillet;[2002-12-31--] Steven T. Watson;[2013-05-01--] Jonathan Knowles;[1998-04-30--2010-04-30] Nicholas J. Grace;[2004-12-31--2013-05-01] Paul A. White;[2009-12-31--2014-05-01] Martin Jacobs;[2012-12-31--] Isabelle de Wismes;";"Steven T. Watson [NA - FC Inconsistent];Jonathan Knowles [NA - FC Inconsistent];Isabelle de Wismes [NA - FC Inconsistent];";11,42;4,56;MSCI ACWI NR USD;XIUSA04EXL;1998-12-31;;;1999-06-30;550 871 257;Yes;No;;;;2014-03-31;2014-04-30;2,38;;-2,01;16,22;16,77;9,07;16,77;0,52;0,80;;;0,80;0,80;0,80;World Stock;39,00;Other;;;VAUSA04BBR;0P0000FPYS;FSUSA00CFF;;;VL Subaccount;Yes;Yes;Yes;Yes;;;;1,16;-0,21;1,66;4,27;2,97;-0,08;-1,11;-0,21;5,33;4,87;-3,89;-0,43;-5,88;-1,19;-1,25;4,53;1,58;-7,44;-2,60;-2,62;-9,88;-19,01;-6,67;5,64;-7,42;-6,15;7,46;10,88;10,30;-0,16;9,70;3,41;5,37;-1,96;4,44;1,98;-4,67;0,91;6,08;-0,75;-9,37;-2,34;8,50;-3,81;10,29;4,14;-2,68;6,86;0,70;3,61;0,36;4,05;-1,92;-1,61;-2,58;-8,25;-9,29;9,97;-1,40;-1,41;6,90;4,95;1,76;-0,32;-8,66;4,80;1,76;2,15;2,61;0,13;2,72;2,55;3,88;-0,08;2,14;2,74;0,74;-2,06;5,69;-2,45;6,80;3,22;2,94;2,73;-4,38;5,42;-1,89;-0,91

Community
  • 1
  • 1
JonM
  • 45
  • 4
  • 1
    what method are you using the get your data from the csv? What is the class for mydata? (type str(mydata)). Even better, if you could provide the first row of mydata[1,]. – luis_js May 13 '14 at 19:50
  • 3
    Good first stab at the question, but a small [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) is strongly recommended ... – Ben Bolker May 13 '14 at 19:55
  • Thanks I will try and provide better data – JonM May 13 '14 at 19:58
  • It looks like you probably should have used `header=TRUE` for a start ... ? – Ben Bolker May 13 '14 at 20:00
  • Thank you (both), that's enough for the vector to work the way the answer was given. To be honest, I don't understand why, but that must be my problem with the unlist command, my apology. If you want to provide an answer I can just close this questions. However, as I had asked, it must be wrong to used the as.vector then – JonM May 13 '14 at 20:05
  • your CSV dump didn't work very well because the separators are missing ... – Ben Bolker May 13 '14 at 20:42

2 Answers2

0

This should work:

mydata <- read.csv(file             = "data.csv",
                   stringsAsFactors = FALSE,
                   sep              = ";",
                   header           = TRUE)
mydata

my.vector <- as.character(mydata[1,])

my.vector will be a character vector

(corrected header = T).

luis_js
  • 611
  • 5
  • 11
  • Thanks, this actually gives the same results as as.numeric given by Ben Bolker, just in characters. Interestingly, they both remove stuff and leave numbesr, I'm sorry I wish I could explain it better. let me try and give both outputs in the question – JonM May 13 '14 at 20:11
  • Could you pleae copy the first 2 lines of the csv file? – luis_js May 13 '14 at 20:31
  • Is possible to maintain the original separators ? and the 2 lines separated? (I don't have too much experience with stackoverflow neither about how to format properly) – luis_js May 13 '14 at 20:43
  • Horribly embarrassing but with this French Excel I can only see the csv as cells, I don't believe it's ever happened to me and I don't know how to change the display option. I can open the .csv and it's saved as a .csv but when I open it, it does not show how it's delimitated, just as normal cells – JonM May 13 '14 at 21:02
  • Don't worry, if you can see the cells in excel, try saving the file as xls (or xlsx), close it and open the newly saved xls file. Then try this http://office.microsoft.com/en-001/excel-help/import-or-export-text-txt-or-csv-files-HP010099725.aspx#BMexport – luis_js May 13 '14 at 21:09
  • Not a great attempt but converting them back from the semi colon using text to column sort of worked to be reproduced. It still gives the feel of the data I suppose, my apologies. – JonM May 13 '14 at 21:09
0

I just use the second set (the one marked as *better) to create a Test4.csv file. It has just one line (as the newline is gone), with the records belonging to 2 lines, so I have used the following commands to read the data and reconstruct the 2 lines with 156 records per line:

mydata <- matrix(unlist(read.csv(file             = "Test4.csv",
                                 stringsAsFactors = FALSE,
                                 sep              = ";",
                                 colClasses       = character(),
                                 header           = FALSE)),
                 nrow         = 2,
                 ncol         = 156,
                 byrow        = TRUE)
head(mydata[1,])
head(mydata[2,])

It seems to be 156 records per line. I don't see any records going a way. Not sure what's happening.

By the way, this method produce a matrix of characters also. Subsetting by row produces character vectors with no lost of data.

str(mydata[1,])
# chr [1:156] "Name" "Base Currency" "Ticker" "ISIN" ...   
length(mydata[1,])
#[1] 156

str(mydata[2,])
# chr [1:156] "Monthly Return 2014-04 Base Currency Hart Sg Ar-American Funds IS Global Growth 2" ...  
luis_js
  • 611
  • 5
  • 11
  • 1
    It's the oddest thing. I wouldn't believe it if I didn't see it, which is why I accept your answer. When I do as you say, creating a Test4.csv with my own data, your method works very well and we don't lose any data. However, when I use the full file (I called it Test2), I get the same results that I posted in the question, with just the numbers. It's a shame that I can't give you my excel file I suppose. Thank you for your help! – JonM May 13 '14 at 22:37