compare_oracle / oraclechunk23.json
xPXXX's picture
Upload 10 files
b34f274
Raw
History Blame Contribute Delete
24 kB
Invalid JSON:Unexpected non-whitespace character after JSONat line 2, column 1
{"QuestionId": 15996275, "AnswerCount": 2, "Tags": "<html5><easeljs><createjs>", "CreationDate": "2013-04-14T06:08:40.730", "AcceptedAnswerId": "16006121", "Title": "How to add large number of circles without losing performance?", "Body": "<p>As I am building my simulator using createljs, I will need to have thousands of little circles ( 3 pixels diameter ).\nI can draw a circle on a shape graph, is this a recommended approach? or shall I use a bitmap?</p>\n\n<p>Any idea about the best way in terms of performance?</p>\n\n<p>Also, is it possible to set text antialias on or off?</p>\n", "Lable": "No"}
{"QuestionId": 16103186, "AnswerCount": 5, "Tags": "<c#><datetime><windows-phone-8>", "CreationDate": "2013-04-19T11:06:40.423", "AcceptedAnswerId": "16103234", "Title": "Convert timestamp string to DateTime object in c#", "Body": "<p>I have timestamp strings in the following format <code>5/1/2012 3:38:27 PM</code>. How do I convert it to a DateTime object in c#</p>\n", "Lable": "No"}
{"QuestionId": 16155597, "AnswerCount": 4, "Tags": "<clojure><functional-programming>", "CreationDate": "2013-04-22T19:57:04.273", "AcceptedAnswerId": "16165102", "Title": "Clojure: What is wrong with my implementation of flatten?", "Body": "<p>I've been working through problems on <a href=\"http://4clojure.com\" rel=\"nofollow\">4Clojure</a> today, and I ran into trouble on <a href=\"http://www.4clojure.com/problem/28\" rel=\"nofollow\">Problem 28</a>, implementing flatten.</p>\n\n<p>There are a couple of definite problems with my code.</p>\n\n<pre><code>(fn [coll]\n ((fn flt [coll res]\n (if (empty? coll)\n res\n (if (seq? (first coll))\n (flt (into (first coll) (rest coll)) res)\n (flt (rest coll) (cons (first coll) res))))) coll (empty coll)))\n</code></pre>\n\n<p>I could use some pointers on how to think about a couple of problems.</p>\n\n<ol>\n<li><p>How do I make sure I'm not changing the order of the resulting list? <code>cons</code> and <code>conj</code> both add elements wherever it is most efficient to add elements (at the beginning for lists, at the end for vectors, etc), so I don't see how I'm supposed to have any control over this when working with a generic sequence.</p></li>\n<li><p>How do I handle nested sequences of different types? For instance, an input of <code>'(1 2 [3 4])</code> will will output <code>([3 4] 2 1)</code>, while an input of <code>[1 2 '(3 4)]</code> will output <code>(4 3 2 1)</code></p></li>\n<li><p>Am I even approaching this from the 'right' angle? Should I use a recursive inner function with an accumulator to do this, or am I missing something obvious?</p></li>\n</ol>\n", "Lable": "No"}
{"QuestionId": 16229851, "AnswerCount": 7, "Tags": "<python><loops>", "CreationDate": "2013-04-26T06:12:22.437", "AcceptedAnswerId": null, "Title": "How can i for loop in parallel in python", "Body": "<p>I have two lists</p>\n\n<pre><code>l1= [1,2,3,4,5,6,7]\nl2 = [1,2,3,4,5,6,7,8,9,77,66,]\n</code></pre>\n\n<p>I want to display them on same lines</p>\n\n<pre><code>\"list1 text\" \"list2 text\"\n\nl1-1 , l2-1\nl1-2 , l2-2\n</code></pre>\n\n<p>and so on</p>\n\n<p>so that if list elements finish then it should display blank <code>\"\"</code> in front of it but other side shows its own elements like</p>\n\n<pre><code>for a,b in l1,l2\n &lt;td&gt;a&lt;/td&gt;&lt;td&gt; b &lt;/td&gt;\n</code></pre>\n", "Lable": "No"}
{"QuestionId": 16374803, "AnswerCount": 1, "Tags": "<bash><sed><awk><xargs>", "CreationDate": "2013-05-04T13:27:22.137", "AcceptedAnswerId": "16374844", "Title": "How to process only one column and convert unix time in text file in BASH", "Body": "<p>I have a text file with table like</p>\n\n<pre><code>367612510.243586 717.860170\n367612512.493918 722.249134\n367668441.429983 692.407935\n367668479.810461 692.407935\n367668482.618858 727.953771\n367668515.150386 727.953771\n</code></pre>\n\n<p>where the first column is UNIX time, and the second is some value. I want to display this list with human readable date and time in BASH. How to do it?</p>\n\n<p>It is possible to do it with additional script file and xargs, but I'm looking for way to do it in one line.</p>\n", "Lable": "No"}
{"QuestionId": 16405909, "AnswerCount": 3, "Tags": "<css><ruby-on-rails><button><twitter-bootstrap>", "CreationDate": "2013-05-06T19:36:17.977", "AcceptedAnswerId": "16406593", "Title": "Twitter bootstrap button problems with Rails (ERB)", "Body": "<p>Why is there such a big difference in my twitter bootstrap button with the two following codes:</p>\n\n<pre><code> &lt;li&gt;&lt;%= link_to 'Post A Ride', home_path, :class =&gt; \"btn btn-success\" %&gt;&lt;/li&gt;\n</code></pre>\n\n<p>and</p>\n\n<pre><code> &lt;li&gt; link_to '&lt;button class=\"btn btn-success\"&gt; Post A Ride &lt;/button&gt;'&lt;/li&gt;\n</code></pre>\n\n<p>I would like the button to be the same as the second code button, the one with ERB is ugly.</p>\n\n<p>It seems the li class and and Nav and Ul is messing with the btn class. How do I override it?</p>\n\n<p>Here is the full code:</p>\n\n<pre><code> &lt;header class=\"navbar\"&gt;\n &lt;div class=\"navbar-inner\"&gt;\n &lt;div class=\"container\"&gt; \n\n &lt;%= link_to \"ALift\", '#', id: \"logo\" %&gt;\n &lt;nav&gt;\n &lt;ul class=\"nav pull-right\"&gt;\n &lt;li&gt;&lt;%= link_to 'Post A Ride', home_path, :class =&gt; \"btn btn-success\" %&gt;&lt;/li&gt;\n &lt;li&gt;&lt;%= link_to \"Search\", '#' %&gt;&lt;/li&gt;\n &lt;li&gt;&lt;%= link_to \"Help\", '#' %&gt;&lt;/li&gt;\n &lt;li&gt;&lt;%= link_to \"Sign in\", '#' %&gt;&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/nav&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n &lt;/header&gt;\n</code></pre>\n\n<p>Any advice.</p>\n", "Lable": "No"}
{"QuestionId": 16453908, "AnswerCount": 1, "Tags": "<python><django><gcc><shared-hosting><psycopg2>", "CreationDate": "2013-05-09T03:35:43.713", "AcceptedAnswerId": null, "Title": "Error installing psycopg2: unrecognized option `-Wdeclaration-after-statement'", "Body": "<p>I'm on a shared hosting provider, trying to install psycopg2 in order to get Django up and running with psql.</p>\n\n<p>I ran <code>$ pip install psycopg2</code></p>\n\n<p>and got following error</p>\n\n<pre><code>gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes \n-fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION=\"2.5 (dt dec pq3 ext)\" \n-DPG_VERSION_HEX=0x080205 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 \n-DHAVE_PQFREEMEM=1 -I/home3/n/norcal/python/include/python2.7 -I. \n-I/usr/local/pgsql-8.2/include -I/usr/local/pgsql-8.2/include/server \n-c psycopg/psycopgmodule.c -o build/temp.linux-i686-2.7/psycopg/psycopgmodule.o \n-Wdeclaration-after-statement\n\ncc1: error: unrecognized option `-Wdeclaration-after-statement'\n\nerror: command 'gcc' failed with exit status 1\n</code></pre>\n\n<p>I did some googling and found that I might be missing python-dev and libpq-dev, but I'm unable to find instructions on how to install those without aptitude - which I don't have access to on my shared hosting provider.</p>\n\n<p>Any ideas?</p>\n\n<p>Thanks a million in advance!</p>\n", "Lable": "No"}
{"QuestionId": 16514277, "AnswerCount": 1, "Tags": "<c#><asp.net><c#-4.0><jquery-1.9>", "CreationDate": "2013-05-13T02:59:24.990", "AcceptedAnswerId": "16514318", "Title": "CheckBox All only works first two times", "Body": "<p>I put a checkbox 'Check All', and my code only works first all check and all uncheked. After that none of the checked box follows the attribute of the checkbox of 'Check All'</p>\n\n<pre><code>&lt;script type=\"text/javascript\"&gt;\n $(function () { \n $('#chkAll').click(function () {\n $('#divChk .chk input:checkbox').attr('checked', function () {\n return $('#chkAll').prop('checked');\n });\n });\n });\n&lt;/script&gt;\n\n\n&lt;body&gt;\n &lt;form id=\"form1\" runat=\"server\"&gt;\n &lt;div class=\"bigDiv\"&gt;\n &lt;asp:CheckBox ID=\"chkAll\" runat=\"server\" Text=\"Check All\" /&gt;&lt;br /&gt;\n &lt;div id=\"divChk\"&gt;\n &lt;asp:CheckBox ID=\"CheckBox1\" runat=\"server\" Text=\"1\" CssClass=\"chk\" /&gt;&lt;br /&gt;\n &lt;asp:CheckBox ID=\"CheckBox2\" runat=\"server\" Text=\"2\" CssClass=\"chk\" /&gt;&lt;br /&gt;\n &lt;asp:CheckBox ID=\"CheckBox3\" runat=\"server\" Text=\"3\" CssClass=\"chk\" /&gt;&lt;br /&gt;\n &lt;asp:CheckBox ID=\"CheckBox4\" runat=\"server\" Text=\"4\" CssClass=\"chk\" /&gt;&lt;br /&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n &lt;/form&gt;\n&lt;/body&gt;\n</code></pre>\n", "Lable": "No"}
{"QuestionId": 16528337, "AnswerCount": 1, "Tags": "<c#><asp.net><sql-server-2008>", "CreationDate": "2013-05-13T18:03:52.573", "AcceptedAnswerId": "16529299", "Title": "stored procedure returns many records but datareader sees only one", "Body": "<p>I created a SQL Server stored procedure in which I use a cursor and I created an ASP.NET method to execute that procedure. I'm using a <code>SqlDataReader</code> and <code>while(reader.Read())</code> to read the values. The problem is that the cursor in the stored procedure returns many rows, but the method reads the first record only. Anyone can help?</p>\n\n<p>stored procedure:</p>\n\n<pre class=\"lang-sql prettyprint-override\"><code>create procedure [dbo].[GetMenusUserGroupCanView] \n(\n @UserGroupID int\n ,@LanguageID int\n) as begin\n\n declare @MenuID int\n\n declare @Title varchar(255)\n\n declare db_cursor cursor for\n (\n select MenuID\n from TrioGate.dbo.Sys_UserGroupMenus\n where UserGroupID=@UserGroupID and ViewFlag='true'\n )\n\n open db_cursor \n\n fetch next from db_cursor into @MenuID \n\n while @@fetch_status = 0 begin \n\n select \n Sys_Menus.MenuID\n ,Sys_Menus.ParentMenuID\n ,Sys_Menus.DescriptionLabelID\n ,Sys_Menus.TitleLabelID\n ,Sys_Menus.TooltipLabelID\n ,Sys_Menus.[Icon]\n ,Sys_Menus.[MenuName]\n ,Sys_Menus.[MenuTypeID] as MenuType\n ,[dbo].[Get_ParentMenu_Name](Sys_Menus.ParentMenuID) as ParentMenuName\n ,[dbo].[Get_Label_Description](Sys_Menus.TitleLabelID,1) as Title\n ,[dbo].[Get_Label_Description](Sys_Menus.TooltipLabelID,1) as Tooltip\n ,[dbo].[Get_Label_Description](Sys_Menus.DescriptionLabelID,1) as [Description]\n ,Sys_Menus.[MainTableName] as [Table]\n ,Sys_Menus.[Seq],Sys_Menus.[MenuPath],Sys_Menus.ActivateLog,Sys_Menus.MenuID \n from Sys_Menus \n left join Sys_LabelDetails\n on Sys_Menus[TitleLabelID] = Sys_LabelDetails[LabelID]\n where Sys_LabelDetails.LanguageID = @LanguageID \n and MenuID = @MenuID \n\n fetch next from db_cursor into @MenuID \n\n end\n\n close db_cursor \n deallocate db_cursor \n\nend\n</code></pre>\n\n<p>Method:</p>\n\n<pre><code>public List&lt;Menu&gt; GetMenusUserGroupCanView(int UserGroupID, int LanguageID)\n{\n List&lt;Menu&gt; list = new List&lt;Menu&gt;();\n SqlCommand cmd = new SqlCommand(\"GetMenusUserGroupCanView \", Connection);\n cmd.CommandType = CommandType.StoredProcedure;\n cmd.Parameters.AddWithValue(\"@UserGroupID\", UserGroupID);\n cmd.Parameters.AddWithValue(\"@LanguageID\", LanguageID);\n try\n {\n\n Connection.Open();\n SqlDataReader reader = cmd.ExecuteReader();\n while (reader.Read())\n {\n Menu entry = new Menu();\n entry.MenuID = (int)reader[\"MenuID\"];\n entry.ParentMenuID = (int)reader[\"ParentMenuID\"];\n entry.ActivateLog = (bool)reader[\"ActivateLog\"];\n entry.Description = reader[\"Description\"].ToString();\n entry.DescriptionLabelID = (int)reader[\"DescriptionLabelID\"];\n entry.Icon = (byte[])reader[\"Icon\"];\n entry.MainTableName = reader[\"Table\"].ToString();\n\n entry.MenuName = reader[\"MenuName\"].ToString();\n entry.MenuPath = reader[\"MenuPath\"].ToString();\n entry.MenuTypeID = reader[\"MenuType\"].ToString();\n entry.ParentMenuName = reader[\"ParentMenuName\"].ToString();\n entry.Seq = (int)reader[\"Seq\"];\n\n entry.Title = reader[\"Title\"].ToString();\n entry.TitleLabelID = (int)reader[\"TitleLabelID\"];\n entry.Tooltip = reader[\"Tooltip\"].ToString();\n entry.ToolTipLabelID = (int)reader[\"ToolTipLabelID\"];\n list.Add(entry);\n }\n\n }\n catch { }\n finally\n {\n Connection.Close();\n }\n return list;\n} \n</code></pre>\n", "Lable": "No"}
{"QuestionId": 16632840, "AnswerCount": 2, "Tags": "<jsf><dynamic><jsf-2>", "CreationDate": "2013-05-19T08:42:41.007", "AcceptedAnswerId": null, "Title": "JSF adding textfields dynamically on click of a button", "Body": "<p>I have written the following code so that I can have a single textfield followed by a add button and a save button at the bottom.</p>\n\n<p>I want the first textfield and add button to be fixed, but whenever a user cicks on add button, a text field gets added below the present textfield and the add button and save button goes down.</p>\n\n<p>I have the following piece of code, but it doesnt seem to working.</p>\n\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&gt;\n&lt;html xmlns=\"http://www.w3.org/1999/xhtml\" \n xmlns:h=\"http://java.sun.com/jsf/html\"\n xmlns:f=\"http://java.sun.com/jsf/core\"\n xmlns:c=\"http://java.sun.com/jstl/core\"\n xmlns:ui=\"http://java.sun.com/jsf/facelets\"&gt;\n&lt;h:head&gt;\n&lt;meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /&gt;\n&lt;title&gt;Dashboard | BlueWhale Admin&lt;/title&gt;\n &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"../css/reset.css\" media=\"screen\" /&gt;\n &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"../css/text.css\" media=\"screen\" /&gt;\n &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"../css/grid.css\" media=\"screen\" /&gt;\n &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"../css/layout.css\" media=\"screen\" /&gt;\n &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"../css/nav.css\" media=\"screen\" /&gt;\n\n&lt;/h:head&gt;\n&lt;body&gt;\n&lt;h:form&gt;\n\n &lt;hr/&gt;\n &lt;h:dataTable id=\"newsinputs\" value=\"#{newsAlerts.values}\" var=\"item\" cellspacing=\"10\"&gt;\n &lt;h:column&gt;\n &lt;h:outputLabel value=\"#{item.label}\" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;\n &lt;/h:column&gt;\n &lt;h:column&gt;\n &lt;h:inputText value=\"#{item.news}\" size=\"100\" /&gt;&lt;br/&gt;\n &lt;/h:column&gt;\n &lt;/h:dataTable&gt;\n\n &lt;h:commandButton styleClass=\"btn btn-blue\" action=\"#{newsAlerts.add()}\" value=\"Add\"&gt;&lt;/h:commandButton&gt;\n &lt;hr/&gt;\n &lt;h:commandButton styleClass=\"btn btn-blue\" action=\"#{newsAlerts.submit}\" value=\"Save\" /&gt;\n\n&lt;/h:form&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>The bean class is as follows</p>\n\n<pre><code>package com.kc.aop.bean;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport javax.faces.bean.ManagedBean;\nimport javax.faces.bean.ViewScoped;\n\nimport com.kc.aop.VO.NewsVO;\n\n@ManagedBean(name = \"newsAlerts\")\n@ViewScoped\npublic class News\n{\n private List&lt;NewsVO&gt; values;\n\n public News()\n {\n this.values = new ArrayList&lt;NewsVO&gt;();\n NewsVO newsVO = new NewsVO();\n newsVO.setLabel(\"News \"+ this.values.size()+1);\n getValues().add(newsVO);\n }\n\n public String submit() {\n\n for(NewsVO newsVO : this.values)\n {\n System.out.println(newsVO.getNews());\n System.out.println(newsVO.getLabel());\n }\n return null;\n // save values in database\n }\n\n\n public List&lt;NewsVO&gt; getValues() {\n return values;\n }\n\n public void setValues(List&lt;NewsVO&gt; values) {\n this.values = values;\n }\n\n\n public String add()\n {\n NewsVO newsVO = new NewsVO();\n newsVO.setLabel(\"News \"+ this.values.size()+1);\n this.values.add(newsVO);\n return \"success\";\n }\n\n\n}\n</code></pre>\n", "Lable": "No"}
{"QuestionId": 16638335, "AnswerCount": 2, "Tags": "<session><express>", "CreationDate": "2013-05-19T18:59:25.977", "AcceptedAnswerId": "16638791", "Title": "express session key property", "Body": "<p>i try to build an app with authentication system in express. for keeping user on session, i use express session middleware. when i configure session, i wonna know, if the session key property have to assign or not. This sample is from some book. </p>\n\n<pre><code>app.configure(function(){\n app.sessionSecret = 'SocialNet secret key';\n app.set('view engine', 'jade');\n app.use(express.static(__dirname + '/public'));\n app.use(express.limit('1mb'));\n app.use(express.bodyParser());\n app.use(express.cookieParser());\n app.use(express.session({\n secret: app.sessionSecret,\n key: 'express.sid',\n store: app.sessionStore\n }));\n mongoose.connect(dbPath, function onMongooseError(err) {\n if (err) throw err;\n });\n});\n</code></pre>\n\n<p>And whats gonna happen, when i don't assign a value to session key?</p>\n", "Lable": "No"}
{"QuestionId": 16640229, "AnswerCount": 1, "Tags": "<ios><uiviewcontroller><container-view>", "CreationDate": "2013-05-19T22:39:57.997", "AcceptedAnswerId": "16644636", "Title": "Is it ok to keep multiple child view controllers associated with a parent UIViewController even when their views are not visible?", "Body": "<p>Scenario: I have a set of objects. I wish to display them using a UITableView when the device is in Portrait mode, and in UICollectionView when it is in landscape. To accomplish this, I want to use a UIViewController as a container, and give it two child view controllers (one each for the UICollectionViewController and UITableViewController). I expect the orientation to change often, resulting in the parent swapping back and forth between the two child controllers.</p>\n\n<p>In the View Controller Programming Guide for iOS (2012-12-13), on pages 117 and 118 where they are talking about the transitions between children, they remove the child view controller from the parent whenever the child's view is removed from the view hierarchy. (See Listing 14-3 in particular.)</p>\n\n<p>Is this necessary for memory or whatever other reasons, or is it ok to keep both child view controllers associated with the parent, and just flip back and forth between the views? Are there performance advantages to either technique?</p>\n", "Lable": "No"}
{"QuestionId": 16679727, "AnswerCount": 1, "Tags": "<r><data.table>", "CreationDate": "2013-05-21T21:24:58.297", "AcceptedAnswerId": "16679847", "Title": "Function for querying a data.table", "Body": "<p>I have a data.table called prices that has 3 columns: ticker, date and price.\nI have run</p>\n\n<pre><code>setkey(prices,ticker,date)\n</code></pre>\n\n<p>If I do this from the code, it works</p>\n\n<pre><code>prices[list(\"MSFT\",as.Date(\"2013-01-15\")]\n</code></pre>\n\n<p>returning only the row for MSFT in 2013-01-15\nHowever, if I write this function</p>\n\n<pre><code>getPrice &lt;- function(ticker,date) {\n prices[list(ticker,date)]\n}\n</code></pre>\n\n<p>it returns the whole data.table\nI suspect that it has something to do with scoping in the i parameter, but I can't get it to work.\nHow do I query the data.table if I don't know the parameters in advance?</p>\n", "Lable": "No"}
{"QuestionId": 16697721, "AnswerCount": 1, "Tags": "<angularjs><angularjs-directive>", "CreationDate": "2013-05-22T17:08:19.987", "AcceptedAnswerId": "16697788", "Title": "How to pass HTML to angular directive?", "Body": "<p>I am trying to create an angular directive with a template, but I also don't want to lose the HTML inside of the div. For example, here is how I would like to call my directive from HTML:</p>\n\n<pre><code>&lt;div my-dir&gt;\n &lt;div class=\"contents-i-want-to-keep\"&gt;&lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>Then, there is my directive:</p>\n\n<pre><code>app.directive('myDir', [ '$compile', function($compile) {\nreturn {\n restrict: 'E',\n link: function(scope, iElement, iAttrs){\n // assigning things from iAttrs to scope goes here\n },\n scope: '@',\n replace: false,\n templateUrl: 'myDir.html'\n};\n}]);\n</code></pre>\n\n<p>and then there is myDir.html, where I define a new element:</p>\n\n<pre><code>&lt;div class=\"example\" style=\"background: blue; height: 30px; width: 30px\"&gt;&lt;/div&gt;\n</code></pre>\n\n<p>Even when I set replace to false, I lose the inner contents-i-want-to-keep div - my understanding of the angular docs was that this would be appended after my template. Is there some way to preserve this (possibly through my linking function?) so that the result will be</p>\n\n<pre><code>&lt;div class=\"example\" style=\"background: blue; height: 30px; width: 30px\"&gt;\n &lt;div class=\"contents-i-want-to-keep\"&gt;&lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>Thanks!</p>\n", "Lable": "No"}
{"QuestionId": 16698048, "AnswerCount": 2, "Tags": "<r><raster><pearson>", "CreationDate": "2013-05-22T17:26:25.723", "AcceptedAnswerId": "16704535", "Title": "R: Calculating Pearson correlation coefficient in each cell along time line", "Body": "<p>I have two sets of rasters, both with same x,y,z extent. I've made two stacks: stacka and stackb. I want to calculate the Pearson correlation coefficient (<a href=\"http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient\" rel=\"nofollow\">PCC</a>) in each grid cell between two stacks along the time line. I've made a simpler example (forgive me with the dumb way of creating rasters)</p>\n\n<pre><code>a1&lt;-c(1,1,1,1,1,1,1,1,NA)\na2&lt;-c(2,2,2,2,1,2,2,NA,2)\na3&lt;-c(3,3,3,3,3,2,NA,3,3)\nb1&lt;-c(2,2,2,2,2,2,2,2,2)\nb2&lt;-c(3,3,3,3,3,3,3,3,3)\nb3&lt;-c(4,4,4,4,4,4,4,4,4)\nmatrixa1&lt;-matrix(a1,3,3)\nmatrixa2&lt;-matrix(a2,3,3)\nmatrixa3&lt;-matrix(a3,3,3)\nmatrixb1&lt;-matrix(b1,3,3)\nmatrixb2&lt;-matrix(b2,3,3)\nmatrixb3&lt;-matrix(b3,3,3)\nrastera1&lt;-raster(matrixa1)\nrastera2&lt;-raster(matrixa2)\nrastera3&lt;-raster(matrixa3)\nrasterb1&lt;-raster(matrixb1)\nrasterb2&lt;-raster(matrixb2)\nrasterb3&lt;-raster(matrixb3)\nstacka&lt;-stack(rastera1,rastera2,rastera3)\nstackb&lt;-stack(rasterb1,rasterb2,rasterb3)\n\na_bar&lt;-calc(stacka,mean,na.rm=TRUE)\nb_bar&lt;-calc(stackb,mean,na.rm=TRUE)\nnumerator&lt;-setValues(rastera1,0)\ndenominator1&lt;-numerator\ndenominator2&lt;-numerator\nfor(i in 1:noflayers){\n numerator&lt;-numerator+(stacka[[i]]-a_bar)*(stackb[[i]]-b_bar)\n denominator1&lt;-denominator1+(stacka[[i]]-a_bar)^2\n denominator2&lt;-denominator2+(stackb[[i]]-b_bar)^2\n}\npearsoncoeff&lt;-numerator/sqrt(denominator1*denominator2)\n</code></pre>\n\n<p>In the end I have a raster with each grid cell filled with PCC. The problem is, data a is intermittent, some grids are NA in some layers. So the end product has some blanks. My algorithm spits out \"NA\" when it encounters NA. I'd need some option like <code>na.rm=TRUE</code> in the calculation, so the output would calculate whatever months have values.</p>\n\n<p>The method I can think of is to use <code>is.na(stacka[[nlayers]][nrows,ncols]==FALSE</code> and find corresponding pair in stackb, but that's on cell basis,which'd take enormous amount of computer time.</p>\n", "Lable": "No"}