emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Vikas Rawal <vikaslists@agrarianresearch.org>
To: Grant Rettke <gcr@wisdomandwonder.com>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Org-mode/R/Latex treatment of NAs
Date: Mon, 14 Jul 2014 05:12:05 +0200	[thread overview]
Message-ID: <EC8DD4EA-85AF-448F-8E5F-33D5DD03F410@agrarianresearch.org> (raw)
In-Reply-To: <CAAjq1meqkdGJ4v9ZyJ5iDtT6VG0cKx0z-Jy4kc1VRdZ+WcOA5g@mail.gmail.com>


> Just wanting to understand more:
> 
> Do you equate nil in Emacs Lisp with NA in R or do you equate it some other way?
> 


When I execute my source code block, the NAs show up in the results block as nil. See example below.

I would prefer a blank in place of nil. Any idea how to do that?

Vikas

--------------


#+NAME: ccpc-negative-income-cerealstate-in
#+BEGIN_SRC R :results value :colnames yes :hline yes
  ccpc[,c(1:5,43,44,45,84,75,76,81,107,10,11,13,12,14:41,46:60,66,67,92,109:114)]->b
  subset(b,Year_Agriculture==2009)->b
  subset(b,Crop_code %in% c(10,20,40,140,150))->b
  (b$Main_Product_Rs+b$By_Product_Rs-b$Cost_A2)->b$Net_income_A2
  (b$Main_Product_Rs+b$By_Product_Rs-b$Cost_C2)/b$Crop_Area_Ha->b$Net_income_C2
  ifelse(b$Net_income_A2<0,1,0)->b$loss
  b$count<-1
  b[,c(16:ncol(b))]*b$Cluster_Factor_Weight*b$Zone_factor->b[,c(16:ncol(b))]
  melt(b,id=c("Year_Agriculture","State","Crop_code","Crop","Zone_Code","Zone_factor","Area_of_Crop_in_Zone_ha","state_multiplier","Tehsil_Code","Size_Group","Period_of_crop_months","Cluster_Factor_Weight","Parcel_Plot_Season","Ha_Month_in_Ground"),m=c("loss","count","Crop_Area_Ha"))->a
  dcast(a,Year_Agriculture+State+Crop_code+Crop+Zone_Code+state_multiplier+Area_of_Crop_in_Zone_ha~variable,sum)->b
  melt(b,id=c("Year_Agriculture","State","Crop_code","Crop","Zone_Code","state_multiplier","Area_of_Crop_in_Zone_ha","Crop_Area_Ha"),m=c("loss","count"))->a
  a$value*a$Area_of_Crop_in_Zone_ha/a$Crop_Area_Ha->a$value
  dcast(a,Year_Agriculture+Crop_code+Crop~variable,sum)->b
  dcast(a,Year_Agriculture+State+Crop_code+Crop~variable,sum)->b1
  b$State<-"All states"
  rbind(b,b1)->b
  round(b$loss*100/b$count,1)->b$prop
  #ggplot(b,aes(x=Year_Agriculture,y=prop,group=State,color=State,linetype=State))->p
  #p+geom_line()+scale_y_continuous("Prportion of farms")+scale_x_continuous("Year",breaks=c(1994,1997,2000,2003,2006,2009),labels=c("1994-95","1997-98","2000-01","2003-04","2006-07","2009-10"))+theme_bw()
  melt(b,id=c("Year_Agriculture","Crop_code","Crop","State","loss","count"))->a
  dcast(a,State~Crop_code,mean,drop=T)->t
  t[is.na(t)]<-NA
  names(t)<-c("State","Wheat","Paddy","Maize","Bajra","Ragi")
  t
#+END_SRC

#+NAME: ccpc-negative-income-cerealstate
#+CAPTION: Proportion of cultivators with negative returns from cultivation of different crops, by State, 2009-10
#+attr_latex: :environment tabulary :width \textwidth :align lRRRRR
#+RESULTS: ccpc-negative-income-cerealstate-in
| State            | Wheat | Paddy | Maize | Bajra | Ragi |
|------------------+-------+-------+-------+-------+------|
| All states       |   2.7 |   7.4 | 23.2  | 6.1   | 15   |
| Andhra Pradesh   |   nil |   5.8 | 17.8  | nil   | 0    |
| Assam            |   nil |   6.5 | nil   | nil   | nil  |
| Bihar            |   nil |   4.8 | nil   | nil   | nil  |
| Chhattisgarh     |  55.3 |   1.2 | 0     | nil   | nil  |
| Gujarat          |     0 |   0.3 | 15.2  | 6.4   | nil  |
| Haryana          |   0.1 |   0.2 | nil   | 3     | nil  |
| Himachal Pradesh |   7.6 |   0.1 | 1.4   | nil   | nil  |
| Jharkhand        |   1.4 |  42.7 | nil   | nil   | nil  |
| Karnataka        |   nil |   2.2 | 3.2   | 39.9  | 14.9 |
| Kerala           |   nil |   8.6 | nil   | nil   | nil  |
| Madhya Pradesh   |     0 |   0.9 | 16.7  | nil   | nil  |
| Maharashtra      |   6.5 |  37.1 | nil   | 15.2  | 18.2 |
| Orissa           |   nil |   0.6 | nil   | nil   | nil  |
| Punjab           |   0.1 |   1.3 | nil   | nil   | nil  |
| Rajasthan        |     0 |   nil | 24    | 0.8   | nil  |
| Tamil Nadu       |   nil |   4.5 | 10.1  | nil   | 0.6  |
| Uttar Pradesh    |   1.1 |   4.2 | 39.3  | 1     | nil  |
| Uttarakhand      |     0 |     0 | nil   | nil   | nil  |
| West Bengal      |  26.9 |   7.5 | nil   | nil   | nil  |


Vikas

  reply	other threads:[~2014-07-14  3:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-13 19:42 Org-mode/R/Latex treatment of NAs Vikas Rawal
2014-07-14  1:39 ` Grant Rettke
2014-07-14  3:12   ` Vikas Rawal [this message]
2014-07-14  3:15     ` Vikas Rawal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EC8DD4EA-85AF-448F-8E5F-33D5DD03F410@agrarianresearch.org \
    --to=vikaslists@agrarianresearch.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=gcr@wisdomandwonder.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).