* Org-mode/R/Latex treatment of NAs
@ 2014-07-13 19:42 Vikas Rawal
2014-07-14 1:39 ` Grant Rettke
0 siblings, 1 reply; 4+ messages in thread
From: Vikas Rawal @ 2014-07-13 19:42 UTC (permalink / raw)
To: org-mode mailing list
I have some tables created by Org-babel/R source codes with NAs. These get exported as “nil” in the latex export. I would like to replace them with blanks.
Any suggestions?
Vikas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org-mode/R/Latex treatment of NAs
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
0 siblings, 1 reply; 4+ messages in thread
From: Grant Rettke @ 2014-07-14 1:39 UTC (permalink / raw)
To: Vikas Rawal; +Cc: org-mode mailing list
Just wanting to understand more:
Do you equate nil in Emacs Lisp with NA in R or do you equate it some other way?
I believe that the data brokering adheres to "expected" mappings as such.
Grant Rettke | ACM, ASA, FSF, IEEE, SIAM
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson
On Sun, Jul 13, 2014 at 2:42 PM, Vikas Rawal
<vikaslists@agrarianresearch.org> wrote:
>
> I have some tables created by Org-babel/R source codes with NAs. These get exported as “nil” in the latex export. I would like to replace them with blanks.
>
> Any suggestions?
>
> Vikas
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org-mode/R/Latex treatment of NAs
2014-07-14 1:39 ` Grant Rettke
@ 2014-07-14 3:12 ` Vikas Rawal
2014-07-14 3:15 ` Vikas Rawal
0 siblings, 1 reply; 4+ messages in thread
From: Vikas Rawal @ 2014-07-14 3:12 UTC (permalink / raw)
To: Grant Rettke; +Cc: org-mode mailing list
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org-mode/R/Latex treatment of NAs
2014-07-14 3:12 ` Vikas Rawal
@ 2014-07-14 3:15 ` Vikas Rawal
0 siblings, 0 replies; 4+ messages in thread
From: Vikas Rawal @ 2014-07-14 3:15 UTC (permalink / raw)
To: Grant Rettke; +Cc: org-mode mailing list
>
>> 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?
>
Replacing NAs with a blank (“”) in R does the trick.
Vikas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-14 3:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-07-14 3:15 ` Vikas Rawal
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).