column layout in R Presentation - r

I'd like to have two columns on a slide in R Presentation, with the column-split after a full-width paragraph, but I can only get this:
I want the "Ice Cream" section to take up the full width of the slide, and the "Ben's Ice Cream Palace" and "Jerry's Ice Cream Castle" sections to appear next to each other below that. Changing the level of the section headings doesn't seem to have any effect. Is there a way to do this?
Troubleshooting
========================================================
## Ice Cream
My town has two ice-cream parlours, Ben's Ice Cream Palace and Jerry's Ice Cream Castle. It would be nice to show the two establishments' flavours side-by-side so that we could compare them easily when deciding where to go buy ice cream on a hot sunny day.
### Ben's Ice Cream Palace
- Chocolate
- Vanilla
- Neopolitan
- Rum Raisin
- Butter Pecan
- Mint Chocolate Chip
***
### Jerry's Ice Cream Castle
- Chocolate
- Vanilla
- Strawberry
- Chunky Monkey
- Chocolate Chip Cookie Dough

Related

How to write “dependent” understanding-when rules?

I’m in a situation like this:
"Cream Corner" by Lynn
An ice cream cone is a kind of edible thing.
An ice cream cone has a number called scoop count.
Rule for printing the name of an ice cream cone:
say "[the scoop count in words]-scoop ice cream cone".
The Cream Corner is a room.
The player holds an ice cream cone with scoop count 3.
Now I want > eat three-scoop to work. I can do this:
Understand "one-scoop" as an ice cream cone
when the scoop count of the item described is 1.
Understand "two-scoop" as an ice cream cone
when the scoop count of the item described is 2.
Understand "three-scoop" as an ice cream cone
when the scoop count of the item described is 3.
[ ... ]
But of course, ideally, I’d like to write a rule like this:
Understand "[number]-scoop" as an ice cream cone
when the scoop count of the item described is the number understood.
However, the Inform documentation specifies that this is impossible:
So we cannot safely say "when the noun is the fir cone", for instance, or refer to things like "the number understood". (We aren't done understanding yet.) If we want more sophisticated handling of such cases, we need to write checking rules and so on in the usual way.
All the same, it isn’t clear to me how to replace such a rule with a checking rule “in the usual way”. How do I use checking rules to make [number]-scoop in the player’s command be interpreted as “an ice cream cone with that many scoops”?
I'm not quite sure what the documentation is implying we do there, but I can help solve the base problem. A partial solution is these two lines:
Understand the scoop count property as referring to an ice cream cone.
Understand "scoop" as an ice cream cone.
This allows the player to type things like three scoop cone or three ice cream cone, and have the three-scoop cone be understood.
This is only a partial solution, as we don't include the dash*, so something like take three-scoop cone wouldn't be understood correctly. The obvious way of solving this problem is by replacing the dash entirely before the command is read, something like this:
[Nonfunctional solution!]
After reading a command:
If the player's command includes "-scoop":
replace the matched text with " scoop";
This doesn't seem to work however, as the above rule matches only whole words--i.e., three -scoop, but not three-scoop. Attempting to do the same with only replacing - fails similarly.
*You can also argue that three ice cream cone shouldn't be a valid match.

How to construct a network from a file of edges

I have the following file:
Apple Pear
Apple Raspberry
Raspberry Pear
Lemon Pear
Lime Plum
Pineapple Grape
As output, I'd like a list of chains of fruits--on each line, associate any two fruits that ever appear together on a line, e.g., one line would be Pineapple, Grape because each appears once and only once, together.
I'm looking for the following output:
Apple Pear Raspberry Lemon
Lime Plum
Pineapple Grape
Does anybody have any suggestions?
Thank you!
It seems you're basically after creating a network of the fruits, so you're best off using the network package (which I just learned about in answering this question, so it's probably got all sorts of functionality I don't understand yet).
To read that text, use read.table(text=...):
x<-read.table(text="Apple Pear
Apple Raspberry
Raspberry Pear
Lemon Pear
Lime Plum
Pineapple Grape")
Then simply create a network object from x:
library(network)
net<-network(x)
For example, you can plot the network:
plot(net)
Haven't quite figured out how to get your exact desired output, but you can see in the plot above that we've achieved the association you wanted. Not sure your end goal, but check out some tutorials for network.

XQuery expression. Something about ordering

I have to order and then print out parts of a text. I've tried some expressions and finally became the code that help me, but I think it isn't really good.
I will post a part of the text and then the code that I've made.
<?xml version="1.0"?>
<recipes>
<recipe>
<title>Beef Parmesan with Garlic Angel Hair Pasta</title>
<ingredient name="beef cube steak" amount="1.5" unit="pound"/>
<ingredient name="onion, sliced into thin rings" amount="1"/>
<ingredient name="green bell pepper, sliced in rings" amount="1"/>
<ingredient name="Italian seasoned bread crumbs" amount="1" unit="cup"/>
<ingredient name="grated Parmesan cheese" amount="0.5" unit="cup"/>
<ingredient name="olive oil" amount="2" unit="tablespoon"/>
<ingredient name="spaghetti sauce" amount="1" unit="jar"/>
<ingredient name="shredded mozzarella cheese" amount="0.5" unit="cup"/>
<ingredient name="angel hair pasta" amount="12" unit="ounce"/>
<ingredient name="minced garlic" amount="2" unit="teaspoon"/>
<ingredient name="butter" amount="0.25" unit="cup"/>
<preparation>
<step>
Preheat oven to 350 degrees F (175 degrees C).
</step>
<step>
Cut cube steak into serving size pieces. Coat meat with the bread crumbs
and parmesan cheese. Heat olive oil in a large frying pan, and saute 1
teaspoon of the garlic for 3 minutes. Quick fry (brown quickly on both sides)
meat. Place meat in a casserole baking dish, slightly overlapping edges.
Place onion rings and peppers on top of meat, and pour marinara sauce
over all.
</step>
<step>
Bake at 350 degrees F (175 degrees C) for 30 to 45 minutes, depending on
the thickness of the meat. Sprinkle mozzarella over meat and leave in the
oven till bubbly.
</step>
<step>
Boil pasta al dente. Drain, and toss in butter and 1 teaspoon garlic. For a
stronger garlic taste, season with garlic powder. Top with grated parmesan
and parsley for color. Serve meat and sauce atop a mound of pasta!
</step>
</preparation>
<comment>
Make the meat ahead of time, and refrigerate over night, the acid in the
tomato sauce will tenderize the meat even more. If you do this, save the
mozzarella till the last minute.
</comment>
<nutrition calories="1167" fat="23" carbohydrates="45" protein="32"/>
</recipe>
<recipe>
<title>Ricotta Pie</title>
<ingredient name="filling">
<ingredient name="ricotta cheese" amount="3" unit="pound"/>
<ingredient name="eggs" amount="12"/>
<ingredient name="white sugar" amount="2" unit="cup"/>
<ingredient name="vanilla extract" amount="2" unit="teaspoon"/>
<ingredient name="semisweet chocolate chips" amount="0.25" unit="cup"/>
<preparation>
<step>
Beat the 12 eggs, 2 cups sugar and vanilla extract together. Stir in
the ricotta cheese and the chocolate chips. Set aside.
</step>
</preparation>
</ingredient>
<ingredient name="dough">
<ingredient name="flour" amount="4" unit="cup"/>
<ingredient name="baking powder" amount="5" unit="teaspoon"/>
<ingredient name="white sugar" amount="1" unit="cup"/>
<ingredient name="shortening" amount="0.5" unit="cup"/>
<ingredient name="eggs, lightly beaten" amount="4"/>
<ingredient name="vanilla extract" amount="1" unit="teaspoon"/>
<preparation>
<step>
Combine the flour, baking powder, and 1 cup of the sugar together. Cut in the
shortening and mix until the mixture resembles coarse crumbs. Mix in 4 of
the eggs and 1 teaspoon of the vanilla. Divide dough into 4 balls and chill (if
needed).
</step>
</preparation>
</ingredient>
<ingredient name="milk" amount="*"/>
<preparation>
<step>
Preheat oven to 325 degrees F (165 degrees C). Grease two deep dish pie
plates.
</step>
<step>
Roll out 2 of the balls to fit into the pie pans. Do not make the crust too thick
as it will expand during cooking and get too thick. Do not flute the edges of
the dough. Roll out the other 2 balls of dough and cut each into 8 narrow
strips for the top of the crust. Alternately you can use cookie cutters and
place the cutouts on the top of the pies.
</step>
<step>
Pour the filling evenly into the pie crusts. Top each pie with 8 narrow strips
of dough or cookie cut-outs. Brush top of pie with milk for shine. Place foil on
the edge of crust.
</step>
<step>
Bake at 325 degrees F (165 degrees C) for 20 to 30 minutes then remove
foil. Continue to bake for another 25 or 30 minutes or until a knife inserted in
the center comes out clean.
</step>
</preparation>
<nutrition calories="349" fat="18" carbohydrates="64" protein="18"/>
</recipe>
> </recipes>
The code I've made is following
<result>
{
for $x in doc()/recipes/recipe
order by $x/nutrition[#calories>600]
return
($x/title) |($x/nutrition[#calories])
}
</result>
The main idea of XQuery expression is to show the title and the calories ordered by calories in <result> tag.
Your first attempt doesn't look that bad, apart from that the result XML doesn't look very useful. You might want to rewrap each title and nutrition in a recipe element. Secondly, your order clause is likely to not do much. You write:
order by $x/nutrition[#calories>600]
But that way you order by the text contents of the nutrition element, which it doesn't have any. You probably meant:
order by $x/nutrition[#calories>600]/#calories
Or perhaps even better, you want to order numerically on calories:
order by $x/nutrition[#calories>600]/#calories/fn:number(.)
HTH!
It is not quite clear to me what you are trying to achieve exactly. So what does the calories > 600 condition stand for (it does not seem to be of much use in the order by clause, as it will just apply to the ordering condition). I would guess, that you want to filter out all nutrition values with less than 600 calories (your current statement would order everything with more than 600 calories, but the others would still appear in the result).
Also, you did miss to put the #calories attribute as the ordering attribute, which I guess is what you want to achieve.
<result>
{
for $x in doc()/recipes/recipe
return ($x/title,
for $n in $x/nutrition[#calories>600]
order by $n/#calories
return $n
)
}
</result>

standardize text using phonetic

i received data from a datacenter and i have to cleanse and make data useful and my biggest problem is one column lets call it "service_description" and for example the data center belong to a hair salon, this column is filled manually (text box) and contain huge amount of data (Billions), here is a small sample
service description
washed the haair
hair washed and dried
used shampoo on har
nails manicure
nail paint
nail pant
paint the nails
what i need to do is get each category together by ruining a script that will analyze each line and give it specif category e.g. hair could be the category for the first three lines because it is repeated in all of them while nail is category for the rest, taking in consideration the category word could be misspelled.
results
service description possible categories
washed the haair hair
hair washed and dried hair
used shampoo on har hair
nails manicure nail
nail paint nail
nail pant nail
paint the nails nail
I'm assuming your categories are fixed lookup.
I would split the string by white spaces; and for each part I would go through all items in your categories lookup, and pick the one with minimum levenshtein distance.
Some references:
http://en.wikipedia.org/wiki/Levenshtein_distance
http://www.codeproject.com/Articles/13525/Fast-memory-efficient-Levenshtein-algorithm

R's XML to Dataframe

I have the next XML Example and I want to get "listing" data in a R dataframe. What's the best way to do it, ex: How would you configure xmlToDataFrame function to do the job starting with an URL?
<response>
<area_name/>
<bounding_box>
<latitude_max>51.667389</latitude_max>
<latitude_min>51.385262</latitude_min>
<longitude_max>0.137236</longitude_max>
<longitude_min>-0.34844</longitude_min>
</bounding_box>
<country>England</country>
<county>London</county>
<latitude>51.5263255</latitude>
<listing>
<agent_address>218a Brick Lane</agent_address>
<agent_logo/>
<agent_name>Salik & Co</agent_name>
<agent_phone>020 3318 7059</agent_phone>
<country/>
<county>London</county>
<description>
Description:
Salik & Co is offering this Commercial Freehold Property for sale on Wise Road, Stratford, London E15... Premises consists of:
12 X 2 Bedroom Flat AS Following-
* 2x Pent House With One Bath
* 2x Flat With 2 Double Bed With 2 Bath
* 8x Flat With 1 Bath
* 4x Car Park
* 4x floor with ground floor parking
* Lift
* Flat 11 & 13 Pent House with 500 sqft Terrace.
* Flat 12 & Ground Floor shop sold for Long lease. Area Profile:
Stratford is a place in the London Borough of Newham in East London. It will be the primary location of the 2012 Summer Olympics. The area is identified in the London Plan as one of 35 major centres in Greater London. Stratford has been a focus of regeneration for some years, and is the location of a number of major projects.... Property Location:
Set only moments from the vibrant amenities of Stratford, Olympic park, Westfield Shopping centre. This modern 2 bed stunning flat offers contemporary accommodation with a private balcony, in a fabulous new eco building close to the green open spaces of East London
Situated on Stratford High Street the property enjoys swift access into the fashionable bars, restaurants and boutiques of Stratford High Street. Transport links include Stratford (Central line, Jubilee Line and British Rail) which provide further link to district line. Price:
Asking price £2.8 million. For further information contact:
Ryan -
Salik -
Office -
Email -
Web -
</description>
<details_url>http://www.zoopla.co.uk/for-sale/details/4507257</details_url>
<displayable_address>Wise Road, London</displayable_address>
<image_caption/>
<image_url>
http://images.zoopla.co.uk/52367ed1b61a63c1b93f1ec0a70d39f83d590c74_354_255.jpg
</image_url>
<latitude>51.53477</latitude>
<listing_id>4507257</listing_id>
<listing_status>sale</listing_status>
<longitude>-0.0045035</longitude>
<num_bathrooms>0</num_bathrooms>
<num_bedrooms>0</num_bedrooms>
<num_floors>0</num_floors>
<num_recepts>0</num_recepts>
<outcode>E15</outcode>
<post_town>London</post_town>
<price>2800000</price>
<price_change>
<date>2010-04-27 00:42:05</date>
<price>3000000</price>
</price_change>
<price_change>
<date>2010-07-04 03:21:14</date>
<price>2800000</price>
</price_change>
<property_type/>
<street_name>Commercial Property</street_name>
<thumbnail_url>
http://images.zoopla.co.uk/52367ed1b61a63c1b93f1ec0a70d39f83d590c74_80_60.jpg
</thumbnail_url>
</listing>
<listing>
<agent_address>Rawlings House 2a Milner Street</agent_address>
<agent_logo>
http://static.zoopla.co.uk/zoopla_static_agent_logo_(29807).gif
</agent_logo>
<agent_name>Marsh & Parsons</agent_name>
<agent_phone>020 3318 6922</agent_phone>
<country/>
<county>London</county>
<description>
A stunning, three bed mews house with spacious, roof terrace in a popular gated development off Milner Street and ideally located for the nearby amenities of South Kensington and Knightsbridge. A large reception room and a contemporary, open plan kitchen occupy the ground floor, while the first floor houses two double bedrooms and a modern family bathroom. An additional shower room can be found on the second floor which also has a substantial area suitable for a third bedroom and access to the sunny roof terrace. Located in the heart SW3's Brompton area, there is a multitude of local amenities available at Chelsea's popular King's Road and Sloane Street, while the shops, bars and restaurants of Brompton Road and Knightsbridge are easily reached. St. Catherine's Mews is ideally located for the Underground stations at both Sloane Square (Circle and District Lines) and South Kensington (Piccadilly, Circle and District Lines) while such a central location provides a number of convenient bus services. For transport links into and out of London the motorways can be accessed via the nearby A4.The property also has planning permission to extend the 2nd floor to encompass some of the roof terrace that would create greater internal square footage.
</description>
<details_url>http://www.zoopla.co.uk/for-sale/details/491528</details_url>
<displayable_address>St Catherines Mews, London SW3</displayable_address>
<floor_plan>
http://content.zoopla.co.uk/5cb125b77de67eb6717bd8a2c74ba7edb6839959.jpg
</floor_plan>
<image_caption>Picture No.46</image_caption>
<image_url>
http://images.zoopla.co.uk/0867139d8bc2e2aac63056d75bbce1677de438c6_354_255.jpg
</image_url>
<latitude>51.493774</latitude>
<listing_id>491528</listing_id>
<listing_status>sale</listing_status>
<longitude>-0.164762</longitude>
<num_bathrooms>0</num_bathrooms>
<num_bedrooms>2</num_bedrooms>
<num_floors>0</num_floors>
<num_recepts>0</num_recepts>
<outcode>SW3</outcode>
<post_town>London</post_town>
<price>1500000</price>
<price_change>
<date>2009-05-16 01:40:29</date>
<price>1350000</price>
</price_change>
<price_change>
<date>2010-02-20 00:30:24</date>
<price>1450000</price>
</price_change>
<price_change>
<date>2011-02-12 00:31:53</date>
<price>1500000</price>
</price_change>
<property_type>Town house</property_type>
<street_name>London</street_name>
<thumbnail_url>
http://images.zoopla.co.uk/0867139d8bc2e2aac63056d75bbce1677de438c6_80_60.jpg
</thumbnail_url>
</listing>
<listing>
<agent_address>175 Putney High Street, Putney</agent_address>
<agent_logo>
http://static.zoopla.co.uk/zoopla_static_agent_logo_(47723).jpeg
</agent_logo>
<agent_name>Foxtons - Putney</agent_name>
<agent_phone>020 3318 9160</agent_phone>
<country/>
<county>London</county>
<description>
A stunning four bedroomed house offering exceptionally spacious accommodation with stylish interior throughout. The property is arranged over four floors and comprises two good-sized reception rooms, generous 29' kitchen/dining room, four bedrooms (two with en suite), two bathrooms, two shower rooms, utility room, guest cloakroom, attractive garden and off-street parking. Akehurst Street is a quiet residential road located close to the green expanses of Richmond Park, and close to amenities in Roehampton with a greater selection of shops, bars and restaurants within easy reach in Putney. The area is well served by a number of local bus routes, while the nearby A3 provides motorists with a fast route into central London and to the South-West.
</description>
<details_url>http://www.zoopla.co.uk/for-sale/details/14226965</details_url>
<displayable_address>Akehurst Street, London</displayable_address>
<image_caption/>
<image_url>
http://images.zoopla.co.uk/5a24b05bff28865405aee72bcf4c46ae2ce299a4_354_255.jpg
</image_url>
<latitude>51.450905</latitude>
<listing_id>14226965</listing_id>
<listing_status>sale</listing_status>
<longitude>-0.242762</longitude>
<num_bathrooms>0</num_bathrooms>
<num_bedrooms>4</num_bedrooms>
<num_floors>0</num_floors>
<num_recepts>0</num_recepts>
<outcode>SW15</outcode>
<post_town>London</post_town>
<price>1499950</price>
<property_type>Town house</property_type>
<street_name>Akehurst Street</street_name>
<thumbnail_url>
http://images.zoopla.co.uk/5a24b05bff28865405aee72bcf4c46ae2ce299a4_80_60.jpg
</thumbnail_url>
</listing>
<listing>
<agent_address>55 Fulham Broadway, Fulham</agent_address>
<agent_logo>
http://static.zoopla.co.uk/zoopla_static_agent_logo_(47732).jpeg
</agent_logo>
<agent_name>Foxtons - Fulham</agent_name>
<agent_phone>020 3318 6868</agent_phone>
<country/>
<county>London</county>
<description>
Located on a quiet residential street in Fulham, this great four bedroomed house offers spacious accommodation with loft conversion and south-facing flat roof. Arranged over three floors, the property comprises reception room with bay window, dining room, kitchen with space to dine and access to the garden, top floor master bedroom with en suite shower room, large second bedroom, two additional bedrooms, bathroom and outside store room. The property is situated on a tree-lined street, ideally located just moments from the local amenities on both Dawes Road and Lillie Road and is within easy reach of a more a comprehensive range of bars, shops and restaurants on nearby Fulham Broadway. The closest underground station is Fulham Broadway (District Line), providing convenient access to various central and greater London destinations.
</description>
<details_url>http://www.zoopla.co.uk/for-sale/details/14351415</details_url>
<displayable_address>Prothero Road, London</displayable_address>
<image_caption/>
<image_url>
http://images.zoopla.co.uk/a9d983b76018a07537de832224bb5174099c2758_354_255.jpg
</image_url>
<latitude>51.48186</latitude>
<listing_id>14351415</listing_id>
<listing_status>sale</listing_status>
<longitude>-0.208447</longitude>
<num_bathrooms>0</num_bathrooms>
<num_bedrooms>4</num_bedrooms>
<num_floors>0</num_floors>
<num_recepts>0</num_recepts>
<outcode>SW6</outcode>
<post_town>London</post_town>
<price>750000</price>
<property_type>Town house</property_type>
<street_name>Prothero Road</street_name>
<thumbnail_url>
http://images.zoopla.co.uk/a9d983b76018a07537de832224bb5174099c2758_80_60.jpg
</thumbnail_url>
</listing>
<longitude>-0.105602</longitude>
<postcode/>
<result_count>76494</result_count>
<street/>
<town/>
</response>
Thank You
Dataframes require that the input data be "rectangular". You clearly do not have such a data arrangement. R's list data type is more appropriate to something like this. The other problem appears to be the presence of ampersands, "&", in this file. Given that "&" is an escape character in html, the safer maneuver here would have been to replace "& " with "&amp ". If you change all of the "&"'s to "and" you can get xmlToList() to read it and create a corresponding list ( but that might damage other files if they had valid HTML buried in them).
The listing data can be extracted by matching 'listing' to the names of the list :
xmlToList(f)[grep("listing", names(xmlToList(f)))]
(You will need to provide an URL.)

Resources