emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Org-mode/R/Latex treatment of NAs


From: Vikas Rawal
Subject: Re: [O] Org-mode/R/Latex treatment of NAs
Date: Mon, 14 Jul 2014 05:12:05 +0200

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]