Mark Knecht
2009-Jun-28 23:02 UTC
[R] newbie - read.csv creates a (data.frame, table, array, matrix, ...) and plotting one column
Hi all, Newbie alert. OK, I'm reading the help file using Ted's suggestion of ?read.csv or ?read.table, etc., and trying to understand exactly what R has created for me when I do the read.csv command. The overall header says read.table creates a 'data.frame', which is fine with me as it works, but throughout the help file I run into the words table, matrix, array and others. Are these just different names for the same thing? Or are they subsets of what R considers a 'data.frame'? Or something else? Maybe just a pointer to a good page in the help file that explains this would be helpful,if it exists? The second question is about plotting one column from data set. I've used read.csv to read in somethign called PFA_VWAP. row.names, names and dim all return sensible values. The command PFA_VWAP_Equity<-PFA_VWAP[,10] seems to load the new variable with the right data for the equity curve, but how do I plot it? plot(PFA_VWAP_Equity) gives me a chart that doesn't make sense to me. Note however that the original values that make up column 10 were surrounded by quotes so I'm not sure how to tell what sort of data R thinks is in column 10. Is it numeric or text? I think it's integer from the last command. Console output is shown below. Thanks in advance for being gentle with a new user. I need to order a good book from Amazon I suppose. Recommendations? Cheers, Mark> row.names(PFA_VWAP)[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" [19] "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" [37] "37" "38" "39" "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "50" "51" "52" "53" "54" [55] "55" "56" "57" "58" "59" "60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72" [73] "73" "74" "75" "76" "77" "78" "79" "80" "81" "82" "83" "84" "85" "86" "87" "88" "89" "90" [91] "91" "92" "93" "94" "95" "96" "97" "98" "99" "100" "101" "102" "103" "104" "105" "106" "107" "108" [109] "109" "110" "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" "121" "122" "123" "124" "125" "126" [127] "127" "128" "129" "130" "131" "132" "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143" "144" [145] "145" "146" "147" "148" "149" "150" "151" "152" "153" "154" "155" "156" "157" "158" "159" "160" "161" "162" [163] "163" "164" "165" "166" "167" "168" "169" "170" "171" "172" "173" "174" "175" "176" "177" "178" "179" "180" [181] "181" "182" "183" "184" "185" "186" "187" "188" "189" "190" "191" "192" "193" "194" "195" "196" "197" "198" [199] "199" "200" "201" "202" "203" "204" "205" "206" "207" "208" "209" "210" "211" "212" "213" "214" "215" "216" [217] "217" "218" "219" "220" "221" "222" "223" "224" "225" "226" "227" "228" "229" "230" "231" "232" "233" "234" [235] "235" "236" "237" "238" "239" "240" "241" "242" "243" "244" "245" "246" "247" "248" "249" "250" "251" "252" [253] "253" "254" "255" "256" "257" "258" "259" "260" "261" "262" "263" "264" "265" "266" "267" "268" "269" "270" [271] "271" "272" "273" "274" "275" "276" "277" "278" "279" "280" "281" "282" "283" "284" "285" "286" "287" "288" [289] "289" "290" "291" "292" "293" "294" "295" "296" "297" "298" "299" "300" "301" "302" "303" "304" "305" "306" [307] "307" "308" "309" "310" "311" "312" "313" "314" "315" "316" "317" "318" "319" "320" "321" "322" "323" "324" [325] "325" "326" "327"> names(PFA_VWAP)[1] "TRADE" "MARK-SYS" "DATE/TIME" "PL/SIZE" "PS METHOD" "POS SIZE" "POS PL" [8] "DRAWDOWN" "DRAWDOWN(%)" "EQUITY"> dim(PFA_VWAP)[1] 327 10> PFA_VWAP_Equity<-PFA_VWAP[,10] > PFA_VWAP_Equity[1] 9,854.00 10,728.00 10,952.00 10,326.00 10,390.00 10,274.00 10,638.00 10,012.00 10,126.00 10,570.00 10,664.00 [12] 11,408.00 11,152.00 11,366.00 11,410.00 10,784.00 11,188.00 10,562.00 10,766.00 11,330.00 10,704.00 10,608.00 [23] 10,812.00 10,186.00 10,300.00 10,044.00 10,028.00 10,072.00 10,006.00 9,870.00 9,794.00 9,748.00 10,002.00 [34] 8,996.00 9,520.00 9,604.00 10,398.00 10,752.00 10,956.00 11,020.00 11,794.00 11,168.00 11,612.00 11,666.00 [45] 11,040.00 10,414.00 10,338.00 10,002.00 9,826.00 9,200.00 9,804.00 10,638.00 10,412.00 10,466.00 9,840.00 [56] 10,404.00 10,508.00 10,872.00 11,156.00 10,030.00 9,404.00 8,778.00 8,722.00 9,016.00 9,340.00 10,034.00 [67] 9,558.00 9,392.00 9,526.00 9,870.00 9,244.00 9,498.00 9,472.00 9,116.00 9,170.00 8,854.00 8,348.00 [78] 7,952.00 8,006.00 8,270.00 8,164.00 8,048.00 8,012.00 8,236.00 8,410.00 8,194.00 8,298.00 8,572.00 [89] 8,636.00 8,350.00 8,354.00 8,348.00 9,122.00 8,846.00 9,940.00 9,994.00 9,368.00 10,292.00 10,186.00 [100] 11,280.00 11,374.00 10,828.00 10,982.00 11,226.00 10,600.00 11,174.00 13,078.00 13,312.00 15,046.00 15,030.00 [111] 15,554.00 16,008.00 15,382.00 14,756.00 14,660.00 15,614.00 14,988.00 15,082.00 15,276.00 15,700.00 15,974.00 [122] 15,548.00 14,922.00 14,296.00 14,640.00 14,764.00 15,238.00 15,232.00 16,416.00 16,650.00 16,024.00 15,398.00 [133] 15,872.00 15,246.00 15,490.00 14,864.00 15,778.00 15,632.00 16,496.00 17,320.00 16,694.00 16,068.00 16,512.00 [144] 16,646.00 17,450.00 18,104.00 18,708.00 19,032.00 19,606.00 19,880.00 19,734.00 19,108.00 20,492.00 21,816.00 [155] 22,280.00 22,554.00 21,928.00 21,302.00 21,396.00 21,670.00 21,944.00 22,378.00 23,692.00 24,036.00 23,750.00 [166] 23,674.00 23,488.00 22,862.00 23,816.00 24,620.00 24,494.00 24,878.00 25,552.00 24,926.00 24,300.00 24,364.00 [177] 24,608.00 23,982.00 24,086.00 23,460.00 23,554.00 22,928.00 23,492.00 22,866.00 22,760.00 23,344.00 24,618.00 [188] 24,982.00 24,976.00 25,280.00 25,744.00 25,118.00 25,112.00 25,336.00 25,830.00 26,364.00 27,958.00 28,232.00 [199] 30,166.00 29,540.00 29,234.00 30,588.00 29,962.00 30,586.00 30,370.00 30,844.00 30,818.00 30,192.00 29,066.00 [210] 30,420.00 30,264.00 31,158.00 31,212.00 31,736.00 31,820.00 32,144.00 31,518.00 31,932.00 31,906.00 31,280.00 [221] 32,034.00 31,748.00 32,672.00 33,136.00 33,490.00 33,494.00 33,768.00 33,142.00 33,346.00 32,720.00 32,744.00 [232] 33,458.00 33,532.00 33,606.00 33,800.00 33,934.00 33,308.00 33,282.00 33,656.00 34,160.00 35,954.00 36,558.00 [243] 36,542.00 35,716.00 36,820.00 37,324.00 37,038.00 37,582.00 40,086.00 40,910.00 41,414.00 41,258.00 41,992.00 [254] 42,146.00 41,520.00 40,834.00 40,208.00 39,582.00 40,416.00 42,720.00 42,094.00 43,328.00 42,702.00 45,546.00 [265] 45,670.00 45,044.00 48,018.00 47,402.00 47,416.00 46,880.00 49,854.00 50,058.00 53,032.00 53,166.00 54,040.00 [276] 53,424.00 53,408.00 52,832.00 52,286.00 52,270.00 51,764.00 51,768.00 51,272.00 50,766.00 50,810.00 50,914.00 [287] 50,358.00 50,352.00 49,826.00 50,330.00 50,404.00 50,468.00 51,052.00 52,006.00 52,460.00 52,464.00 51,558.00 [298] 51,532.00 51,536.00 51,540.00 51,964.00 52,018.00 52,132.00 52,076.00 54,150.00 55,954.00 55,468.00 57,772.00 [309] 57,816.00 57,330.00 57,314.00 58,428.00 57,912.00 57,376.00 58,080.00 58,084.00 58,338.00 57,752.00 57,276.00 [320] 57,310.00 56,304.00 56,498.00 55,892.00 56,446.00 56,920.00 57,004.00 56,648.00 322 Levels: 10,002.00 10,006.00 10,012.00 10,028.00 10,030.00 10,034.00 10,044.00 10,072.00 10,126.00 ... 9,994.00> > typeof(PFA_VWAP)[1] "list"> typeof(PFA_VWAP[,10])[1] "integer">
Mark Knecht
2009-Jun-29 01:14 UTC
[R] newbie - read.csv creates a (data.frame, table, array, matrix, ...) and plotting one column
On Sun, Jun 28, 2009 at 4:02 PM, Mark Knecht<markknecht at gmail.com> wrote:> Hi all, > ? Newbie alert.<SNIP>> > ? The second question is about plotting one column from data set. > I've used read.csv to read in somethign called PFA_VWAP. row.names, > names and dim all return sensible values. The command > PFA_VWAP_Equity<-PFA_VWAP[,10] seems to load the new variable with the > right data for the equity curve, but how do I plot it? > plot(PFA_VWAP_Equity) gives me a chart that doesn't make sense to me. > Note however that the original values that make up column 10 were > surrounded by quotes so I'm not sure how to tell what sort of data R > thinks is in column 10. Is it numeric or text? I think it's integer > from the last command.<SNIP> So I've tried to boil this down to the something simple others can try and duplicate my confusion, or just see what's going on from this post. Basically I'm trying to get a handle on the difference between a list and an array, and how to take my data read with read.csv and plot it on a scatter chart. 1) Here's a small portion of one of my data files. I put this at C:\Test1.csv PORTFOLIO EQUITY TABLE TRADE,MARK-SYS,DATE/TIME,PL/SIZE,PS METHOD,POS SIZE,POS PL,DRAWDOWN,DRAWDOWN(%),EQUITY 1,1,1/9/2004 1:11:00 PM,-146.00,As Given,1,-146.00,146.00,1.460,"9,854.00" 2,1,1/12/2004 1:11:00 PM,874.00,As Given,1,874.00,0.00,0,"10,728.00" 3,1,1/13/2004 1:11:00 PM,224.00,As Given,1,224.00,0.00,0,"10,952.00" 4,1,1/28/2004 12:28:00 PM,-626.00,As Given,1,-626.00,626.00,5.716,"10,326.00" 5,1,2/9/2004 1:11:00 PM,64.00,As Given,1,64.00,562.00,5.131,"10,390.00" 6,1,2/13/2004 1:11:00 PM,-116.00,As Given,1,-116.00,678.00,6.191,"10,274.00" 7,1,2/20/2004 1:11:00 PM,364.00,As Given,1,364.00,314.00,2.867,"10,638.00" 8,1,2/23/2004 11:23:00 AM,-626.00,As Given,1,-626.00,940.00,8.583,"10,012.00" 9,1,2/24/2004 1:11:00 PM,114.00,As Given,1,114.00,826.00,7.542,"10,126.00" 10,1,2/25/2004 1:11:00 PM,444.00,As Given,1,444.00,382.00,3.488,"10,570.00" (In case of line breakage everything from TRADE to EQUITY is on line 2 and there are 10 lines that follow making 12 lines total.) 2) I read this into R creating T1 using the command T1<-read.csv("C:\\Test1.csv",skip=1,header=TRUE) 3) If I type T1 and hit return then I see the data. 4) dim(T1) says 10 10 which is correct. 5) I can read the two columns I want to use to create the scatter plot using:> T1[,1][1] 1 2 3 4 5 6 7 8 9 10> T1[,10][1] 9,854.00 10,728.00 10,952.00 10,326.00 10,390.00 10,274.00 10,638.00 10,012.00 10,126.00 10,570.00 Levels: 10,012.00 10,126.00 10,274.00 10,326.00 10,390.00 10,570.00 10,638.00 10,728.00 10,952.00 9,854.00>Now, here's the confusion. plot(T1[,1],T1[,10]) creates a plot, but the range on both X & Y is 1-10. I want 1-10 on the X axis but need the values in the first line of the T1[,10] return as the Y axis. How can I create that scatter plot? Thanks, Mark