knavero
2012-Mar-20 04:34 UTC
[R] Wrong output due to what I think might be a data type issue (zoo read in problem)
Here's the small scale version of the R script: http://pastebin.com/sEYKv2Vv Here's the file that I'm reading in: http://r.789695.n4.nabble.com/file/n4487682/weatherData.txt weatherData.txt I apologize for the length of the data. I tried to cut it down to 12 lines, however, it wasn't reproducing the bad output that I wanted to show. The problem is that my whole data set shifts down. For example, I have this when the raw data is read in or scanned in as a zoo object: "> rawData (12/01/10 00:53:00) (12/01/10 01:53:00) (12/01/10 02:53:00) (12/01/10 03:53:00) 41 40 39 38 (12/01/10 04:53:00) (12/01/10 05:53:00) (12/01/10 06:53:00) (12/01/10 07:53:00) 38 37 36 39 (12/01/10 08:53:00) (12/01/10 09:53:00) (12/01/10 10:53:00) (12/01/10 11:53:00) 43 47 50 " Then when I run it through my code, which should feed out the exact same thing (the values at least), the output is this: "> intData (12/01/10 00:53:00) (12/01/10 01:53:00) (12/01/10 02:53:00) (12/01/10 03:53:00) 11.0 10.0 9.0 8.0 (12/01/10 04:53:00) (12/01/10 05:53:00) (12/01/10 06:53:00) (12/01/10 07:53:00) 8.0 7.0 6.0 9.0 (12/01/10 08:53:00) (12/01/10 09:53:00) (12/01/10 10:53:00) (12/01/10 11:53:00) 13.0 17.0 20.0 24.0 " Finally, my dput(rawData) and dput(intData): "> dput(rawData) structure(c(11L, 10L, 9L, 8L, 8L, 7L, 6L, 9L, 13L, 17L, 20L, 24L, 27L, 27L, 27L, 26L, 23L, 21L, 20L, 21L, 18L, 16L, 14L, 14L, 12L, 10L, 12L, 11L, 10L, 10L, 11L, 14L, 16L, 20L, 23L, 27L, 25L, 26L, 29L, 28L, 27L, 26L, 24L, 24L, 25L, 24L, 23L, 23L, 21L, 20L, 18L, 19L, 18L, 18L, 16L, 18L, 21L, 24L, 25L, 27L, 27L, 29L, 29L,..." "> dput(intData) structure(c(11, 10, 9, 8, 8, 7, 6, 9, 13, 17, 20, 24, 27, 27, 27, 26, 23, 21, 20, 21, 18, 16, 14, 14, 12, 10, 12, 11, 10, 10, 11, 14, 16, 20, 23, 27, 25, 26, 29, 28, 27, 26, 24, 24, 25, 24, 23, 23, 21, 20, 18, 19, 18, 18, 16, 18, 21, 24, 25, 27, 27, 29, 29, 28, 26, 25, 24, 22, 22, 22, 21, 21, 21, 20, 21, 21, 20, 21,..." I am not sure how to interpret this, however I have tried researching on what the "L" following the number is, and it seems they are "list" values? Also, I have read ?colClasses in the R manual, and have tried colClasses.>From experience using C, there seems to be a related error message saying:"scan() expected 'a real', got 'M'" What is "M"? Is that matrix? Any clarification of the issue and solution is appreciated. I apologize in advance for any noob mistake related to asking questions correctly according to forum specifications. Thanks for any help! I will keep messing around with colClasses....I feel like I am close to a solution..however, am very far from understanding the problem. -- View this message in context: http://r.789695.n4.nabble.com/Wrong-output-due-to-what-I-think-might-be-a-data-type-issue-zoo-read-in-problem-tp4487682p4487682.html Sent from the R help mailing list archive at Nabble.com.
knavero
2012-Mar-20 05:24 UTC
[R] Wrong output due to what I think might be a data type issue (zoo read in problem)
found a temporary fix (I'm sure it's redundant and not as elegant, but here it is): require(zoo) require(chron) setwd("/home/knavero/Desktop/") fmt = "%m/%d/%Y %H:%M" tail1 = function(x) tail(x, 1) rawData = read.zoo("weatherData.txt", header = T, FUN = as.chron, format = fmt, sep = "\t", aggregate = tail1) #colClasses = c(NA, "matrix")) rawData = zoo(cbind(temp = as.vector(rawData)), time(rawData)) oneMin = seq(start(rawData), end(rawData), by = times("01:00:00")) intData = na.approx(rawData, xout = oneMin) par(mfrow = c(3, 1), oma = c(0, 0, 2, 0), mar = c(2, 4, 1, 1)) plot(rawData, type = "p", ylim = c(0, 100)) grid(col = "darkgrey") plot(intData, type = "p", ylim = c(0, 100)) grid(col = "darkgrey") Silly coding huh? It works though....the plots were just to double check btw...nothing significant obviously -- View this message in context: http://r.789695.n4.nabble.com/Wrong-output-due-to-what-I-think-might-be-a-data-type-issue-zoo-read-in-problem-tp4487682p4487739.html Sent from the R help mailing list archive at Nabble.com.
knavero
2012-Mar-20 09:46 UTC
[R] Wrong output due to what I think might be a data type issue (zoo read in problem)
update temporary fix: http://pastebin.com/dzj0W89H -- View this message in context: http://r.789695.n4.nabble.com/Wrong-output-due-to-what-I-think-might-be-a-data-type-issue-zoo-read-in-problem-tp4487682p4488179.html Sent from the R help mailing list archive at Nabble.com.
Joshua Ulrich
2012-Mar-20 10:44 UTC
[R] Wrong output due to what I think might be a data type issue (zoo read in problem)
On Mon, Mar 19, 2012 at 11:34 PM, knavero <knavero at gmail.com> wrote:> Here's the small scale version of the R script: > > http://pastebin.com/sEYKv2Vv > > Here's the file that I'm reading in: > > http://r.789695.n4.nabble.com/file/n4487682/weatherData.txt weatherData.txt > > I apologize for the length of the data. I tried to cut it down to 12 lines, > however, it wasn't reproducing the bad output that I wanted to show. ><snip>> > Finally, my dput(rawData) and dput(intData): > > "> dput(rawData) > structure(c(11L, 10L, 9L, 8L, 8L, 7L, 6L, 9L, 13L, 17L, 20L, > 24L, 27L, 27L, 27L, 26L, 23L, 21L, 20L, 21L, 18L, 16L, 14L, 14L, > 12L, 10L, 12L, 11L, 10L, 10L, 11L, 14L, 16L, 20L, 23L, 27L, 25L, > 26L, 29L, 28L, 27L, 26L, 24L, 24L, 25L, 24L, 23L, 23L, 21L, 20L, > 18L, 19L, 18L, 18L, 16L, 18L, 21L, 24L, 25L, 27L, 27L, 29L, 29L,..." > > "> dput(intData) > structure(c(11, 10, 9, 8, 8, 7, 6, 9, 13, 17, 20, 24, 27, 27, > 27, 26, 23, 21, 20, 21, 18, 16, 14, 14, 12, 10, 12, 11, 10, 10, > 11, 14, 16, 20, 23, 27, 25, 26, 29, 28, 27, 26, 24, 24, 25, 24, > 23, 23, 21, 20, 18, 19, 18, 18, 16, 18, 21, 24, 25, 27, 27, 29, > 29, 28, 26, 25, 24, 22, 22, 22, 21, 21, 21, 20, 21, 21, 20, 21,..." > > I am not sure how to interpret this, however I have tried researching on > what the "L" following the number is, and it seems they are "list" values?1 is a double. 1L is an integer.> class(1)[1] "numeric"> class(1L)[1] "integer"> Also, I have read ?colClasses in the R manual, and have tried colClasses. > >From experience using C, there seems to be a related error message saying: > > "scan() expected 'a real', got 'M'" > > What is "M"? Is that matrix? Any clarification of the issue and solution isThere is an "M" in your data at line 9954: 1/3/2012 9:53 48 1/3/2012 10:53 M 1/3/2012 11:53 51> appreciated. I apologize in advance for any noob mistake related to asking > questions correctly according to forum specifications. Thanks for any help! > I will keep messing around with colClasses....I feel like I am close to a > solution..however, am very far from understanding the problem. >Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com R/Finance 2012: Applied Finance with R www.RinFinance.com