Following my previous posts on how to read/write Excel files from Matlab here is the way I use to read/write Excel files from R. Again it seems the Apache POI java library made developers’life easy. I use here the simple-yet-powerful xlsx package (documentation here in PDF; project website).
Here you don’t need to install any additional files, installing the xlsx package from R does all the dirty work that for you. Then, reading an Excel file is very easy:
libary(xlsx) inData <- read.xlsx2("input.xls", sheetName="Contactmatrix", header=FALSE)
I usually use
read.xlsx2 instead of
read.xlsx. It is said to be faster with large matrices and I had the opportunity to experience it – so I stick with this. You can read
xlsm files without issue (well, with the simple formatting I usually use).
Writing to an Excel file is also very easy:
write.xlsx2(outData, "output.xls", sheetName="Random2", col.names=FALSE, row.names=FALSE)
Easy, isn’t it?
Last week Google announced it will shut down its Reader service. It is a web-based RSS reader. It therefore allows to be kept updated of news from around the net in a central location. I like
d the service for 3 reasons (on top of the fact it’s free, 0$, to use):
- It’s web-based, accessible from anywhere/everywhere with a simple browser;
- It’s text-based, you can quickly scan headlines and use the powerful search function from Google;
- It’s backed by an API so you can use it via different apps on different platforms and they all stay synchronised (the web/mobile version of Reader is not as efficient as the web/desktop version; hence the proliferation of apps using Reader as a backbone).
Of course it frustrated a lot of people, from scientists to consultants … to name a few only. People are looking for alternative (you can do a search on Google while the Search service is still working). Feedly is cited very often as the next best alternative. However its nice, graphical interface conflicts with my second reason to like Google Reader: it’s text-based. The Old Reader looks also interesting, it is text-based but no apps on different platforms yet. But both are also proprietary and can be turned off (or changed to a pay-for-use model) at any moment
An interesting solution could be an Evernote RSS reader. Evernote has already a portfolio of application ranging from a note-taking software, screenshots, drawing, food, … They have a synchronisation process in place. Why not a RSS reader then?
Back to the main track … Fortunately – in a way – Google Takeout allows you to retrieve all your data from Reader, along with an OPML file containing all your subscriptions. You can feed this file in another reader and you can go forward. Starred items are also retrieved (but which reader can use them?). And if you are interested The Guardian has an interesting article about the average duration of Google free services (1459 days, see below) and other nice facts. I guess they will keep Search alive
But what can be done for free (as in free speech)? One of the solution is Owncloud (AGPL) and they recently released a RSS reader add-on. Another solution could be pyAggr3g470r, a news aggregator written in Python. And I was wondering why there isn’t just a simple API that would allow any kind of application to connect, update and display RSS feed. Something like the NewsCredNews API but free, simpler to use than Owncloud and with apps/website interface for mobile devices. And a poney with that, please.
Do you have any other solution?
I was trying to reproduce the map of the GAVI Alliance eligible countries (btw I was surprised India is eligible – but that’s the beauty of relying on numbers only and not assumptions) in R. This is the original map (there are 57 countries eligible):
I started to use the R package rworldmap because it seemed the most appropriate for this task. Everything went fine. Most of the time was spent converting the list of countries from plain English to plain “ISO3″ code as required (ISO3 is in fact ISO 3166-1 alpha-3). I took my source from Wikipedia.
Well, that was until
joinCountryData2Map gave me this reply:
54 codes from your data successfully matched countries in the map
3 codes from your data failed to match with a country code in the map
189 codes from the map weren’t represented in your data
I should have
better simply read the documentation: there is another small command that needs not to be overlooked,
rwmGetISO3. What are the three codes that failed to match?
Although you can compare visually the map produced with the map above, R (and rworldmap) can indirectly give you the culprits:
tC2 = matrix(c("Afghanistan", "Bangladesh", "Benin", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Central African Republic", "Chad", "Comoros", "Congo, Dem Republic of", "Côte d'Ivoire", "Djibouti", "Eritrea", "Ethiopia", "Gambia", "Ghana", "Guinea", "Guinea Bissau", "Haiti", "India", "Kenya", "Korea, DPR", "Kyrgyz Republic", "Lao PDR", "Lesotho", "Liberia", "Madagascar", "Malawi", "Mali", "Mauritania", "Mozambique", "Myanmar", "Nepal", "Nicaragua", "Niger", "Nigeria", "Pakistan", "Papua New Guinea", "Rwanda", "São Tomé e Príncipe", "Senegal", "Sierra Leone", "Solomon Islands", "Somalia", "Republic of Sudan", "South Sudan", "Tajikistan", "Tanzania", "Timor Leste", "Togo", "Uganda", "Uzbekistan", "Viet Nam", "Yemen", "Zambia", "Zimbabwe"), nrow=57, ncol=1) apply(tC2, 1, rwmGetISO3)
In the results, some countries are actually given in a slightly different way by GAVI than in R. For instance “Congo, Dem Republic of” should be changed for rworldmap in “Democratic Republic of the Congo” (ISO3 code: COD). Or “Côte d’Ivoire” should be changed for rworldmap in “Ivory Coast” (ISO3 code: CIV). An interesting resource for country names recognised by rworld map is the UN Countries or areas, codes and abbreviations. Once you correct this, you can have your map of GAVI-eligible countries:
And here is the code:
# Displays map of GAVI countries library(rworldmap) theCountries <- c("AFG", "BGD", "BEN", "BFA", "BDI", "KHM", "CMR", "CAF", "TCD", "COM", "COD", "CIV", "DJI", "ERI", "ETH", "GMB", "GHA", "GIN", "GNB", "HTI", "IND", "KEN", "PRK", "KGZ", "LAO", "LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MOZ", "MMR", "NPL", "NIC", "NER", "NGA", "PAK", "PNG", "RWA", "STP", "SEN", "SLE", "SLB", "SOM", "SDN", "SSD", "TJK", "TZA", "TLS", "TGO", "UGA", "UZB", "VNM", "YEM", "ZMB", "ZWE") GaviEligibleDF <- data.frame(country = c("AFG", "BGD", "BEN", "BFA", "BDI", "KHM", "CMR", "CAF", "TCD", "COM", "COD", "CIV", "DJI", "ERI", "ETH", "GMB", "GHA", "GIN", "GNB", "HTI", "IND", "KEN", "PRK", "KGZ", "LAO", "LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MOZ", "MMR", "NPL", "NIC", "NER", "NGA", "PAK", "PNG", "RWA", "STP", "SEN", "SLE", "SLB", "SOM", "SDN", "SSD", "TJK", "TZA", "TLS", "TGO", "UGA", "UZB", "VNM", "YEM", "ZMB", "ZWE"), GAVIeligible = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) GAVIeligibleMap <- joinCountryData2Map(GaviEligibleDF, joinCode = "ISO3", nameJoinColumn = "country") mapCountryData(GAVIeligibleMap, nameColumnToPlot="GAVIeligible", catMethod = "categorical", missingCountryCol = gray(.8))
- more activated products per day and per year in 2011,
- more Samsung Galaxy S3 (running Android) sold in Q3 2012 than iPhone4 and 5S (running iOS),
- more devices worldwide,
- catching up Apple’s market share in tablets,
All this is summarised in an infographics MBA Online designed (the original address is here: http://www.mbaonline.com/android/ – click at your own risk). It is sweet and colorful, with lots of numbers and some references in the end. Unfortunately these references are embedded in the image so you cannot click on them if you ever want to read more info.
Also as I mentioned previously (for an infographics coming from a similar type of website), I didn’t like much the fact it was very, very long (see reduced copy on the right). It makes things easily read while scrolling down. But ymmv I would have like something a bit more different. For instance I would have seen this more as a succession of slides, a-la Pechakucha maybe (except there is a lot of text). But the restrictive license (CC-by-nc-nd) prohibits derivative works.
So I like my Android device. I like when people promote it, are proud that Android is a success and talk about it. And the web is full of these infographics: a similar story about taking over the world, the successive Android versions (again very long), tastes of Android users (versus iOS users’), a broader smartphone comparison (again very long), a Google search for it, … Choose the one you like!
If you are using Matlab on a MS-Windows PC with MS-Excel installed, there is no problem reading and writing data to Excel (in case your users/customers only understand this software but you still want to do the computations in Matlab). Here is the code to read (1st line) and write (2nd line):
inputs = xlsread('inputfile.xls', 'inData', 'A1:B3'); [writeStatus, writeMsg] = xlswrite('outputfile.xls', myMatrix, 'outData', 'A1');
Now, there are several reasons why you may not be able to read and write directly to an Excel file: you have Matlab but
- you are on MS-Windows but MS-Excel is not installed (if you use OpenOffice.org, csv files in general or on a server where even Microsoft discourage the use of Excel in back-end, see “More information” here);
- you are on MacOS;
- you are on Linux;
Matlab provides a basic way to read and write in these cases:
xlsread() will only read some xls files (saved as version 97-2003, which should not be an issue – at least this is an Excel file) ;
xlswrite() will only write a .csv file. So you can’t deliver the Excel output.
Fortunately Open Source software is here to help you!
Indeed two recently published code on Matlab Central allow you to write “directly” to Excel.
The first solution is provided by Marin Deresco and apparently uses his own binder to Excel. The most simple code is:
display(['Add Java paths']); javaaddpath('D:\JExcelAPI\jxl.jar'); javaaddpath('D:\JExcelAPI\MXL.jar'); display(['Writing matrix to file']); writeStatus = xlwrite('output.xls', myMatrix, 'outData'); display(['writeStatus: "' num2str(writeStatus) '"']); % 1 = success, 0 = failure
I advise you to put the two .jar files in a central location (as done in the code above). That way all you functions will have access to the same version of these files (and updating them for all your projects will be much easier).
But there are three small issues. First the generated matrix will contain only text fields (and they are formatted as text fields, not numbers) ; it doesn’t really matter because Excel can then use this text as numbers directly. Then the second issue is that although it will actually write the requested data, there will be an error when opening the Excel file if you specified a sheet (‘outData’ here) that already exists. Finally you can only start writing at A1.
The second solution is provided by Alec de Zegher, partly in response to the limitation of the previous code. Alec is taking advantage of the Apache POI java library to handle the writing-side. His code also allows to start writing anywhere in the sheet. And it uses the same call structure:
display(['Add Java paths']); javaaddpath('D:\poi_library\poi-3.8-20120326.jar'); javaaddpath('D:\poi_library\poi-ooxml-3.8-20120326.jar'); javaaddpath('D:\poi_library\poi-ooxml-schemas-3.8-20120326.jar'); javaaddpath('D:\poi_library\xmlbeans-2.3.0.jar'); javaaddpath('D:\poi_library\dom4j-1.6.1.jar'); display(['Writing matrix to file']); writeStatus = xlwrite('output.xls', myMatrix, 'outData', 'B2'); display(['writeStatus: "' num2str(writeStatus) '"']); % 1 = success, 0 = failure
As you can see there are some more .jar to add. On the other hand, it uses a syntax that is very similar to the previous one and to the original Matlab command. Thanks, Marin and Alec, for this great help!
This was tested on Matlab R2012a on a Windows XP 64-bits and with the MCR (same version) on a Windows 2008 64-bits – according to the respective pages for the code, it should work on Mac and other platforms/configurations too.
Photo credits: matlab rubiks cube by gusset, on Flickr (licence by-nc-sa)
Tonight I was wondering what was Android market share in Asia. It is 31% according to a recent study from Ericsson’s ConsumerLab group (reported by TechRepublic). Although dominant through most studied countries, Android is not dominant in Singapore (iOS has 46%), in Indonesia (RIM has 29%) nor in Vietnam (Symbian has 26%).
Last year ABI Research released a study where they showed that Android-based smartphones market share grew from 16% in 2010 to 52% in 2011 (but this included tablets and did not cover exactly the same countries as the Ericsson study). Voila
This time Merck & co. stopped the clinical trial MK-0431E studying the co-administration of Sitagliptin and Atorvastatin in inadequately controlled Type 2 Diabetes Mellitus. Merck cites “business reasons” without further explanations.
Sitagliptin is sold under the trade name Januvia. It is an oral antihyperglycemic and one of the (if not the) best selling product of Merck with US$975 million revenue in the third quarter of 2012. On the other hand Atorvastatin is a statin lowering blood cholesterol. It was a blockbuster for Pfizer (sold under the trade name of Lipitor) until its patent expired.
Combining these two molecules made biological sense in order to reduce the number of medications that diabetic patients take. Of course combining two blockbusters (including one which patent expired) is a nice attempt to maintain drugs and positions on market.
Happy Halloween! It’s the season for Q3 reports a bit everywhere so also in Pharma: Abbott (↑), Elan (↑), Eli Lilly (↓), Bristol-Myers Squibb (↓), Sanofi (↓), Novartis (↓), Shire (↑), AstraZeneca (↓), Merck & Co (↑), Novo Nordisk (↑), GlaxoSmithKline (↓), …
At approximately the same time came a FirstWord List about the largest layoffs in Pharma so far (2012) … I just plotted the losses so far below. Spooky!
We had a fixed phone line at home. We had a fixed phone line on our desk at the office. There was a letterbox in front of the house and a pigeon hole at some central location in the office.
And we were not reachable when sleeping, when in meeting, when commuting, …
We have a fixed phone line at home. We have a fixed phone line on our desk at the office. We have a mobile phone in our pocket or connected to the hands-free system in the car. The computers and tablet are running Skype or another communication software that shows every contact if we are “available”, “busy” or “not to be disturbed”. There are still letterboxes and pigeon holes but also e-mails, instant messaging, …
The fixed lines fall back on the mobile if there is no answer after 5 tones. We are reachable when sleeping, when in meeting, when commuting, … People call you when you don’t answer their e-mail after 5-10 minutes.
I will be abroad, following some conference. What if I only carry a wifi-enabled music player running just Skype? I will be reachable between talks not during talks, at the conference center but not when commuting, at the hotel but not when reading or sleeping. Will it really make a difference? I wish I were not that connected.
P.S. of course this is a first world problem: