I tried to include the summary of an lm object in an Rmd file, using code like the following but it didn't work. Could you help me do that?
```{r summary_lm, results='asis', echo=FALSE, comment=NA}
library(apsrtable)
my_model <- lm(y ~ x, data = data.frame(y = rnorm(10), x = 1:10))
res <- apsrtable(my_model) # my_model is a linear regression model (lm)
cat("$$latex \n",res,"\n$$ \n")
```
The $$ syntax only applies to math expressions, and you were trying to put a table in it, which will not work. The apsrtable, as far as I understand, is for LaTeX only, but LaTeX and Markdown are very different -- there is little hope you can redo LaTeX entirely with Markdown. I think people invented the $$ syntax for Markdown due to the fact that it is well supported by MathJax, and also note there are many variants/flavors based on the original Markdown.
At the moment you may consider:
use the xtable or ascii or R2HTML package to generate HTML tables
request the package author of apsrtable to support HTML tables
What about including my_model in Markdown format with `panderĖ:
> library(pander)
> pander(my_model)
--------------------------------------------------------------
Estimate Std. Error t value Pr(>|t|)
----------------- ---------- ------------ --------- ----------
**x** 0.1174 0.1573 0.7465 0.4767
**(Intercept)** -0.2889 0.9759 -0.296 0.7748
--------------------------------------------------------------
Table: Fitting linear model: y ~ x
Or in PHP MarkdownExtra/rmarkdown format:
> panderOptions('table.style', 'rmarkdown')
> pander(my_model)
| | Estimate | Std. Error | t value | Pr(>|t|) |
|:-----------------:|:----------:|:------------:|:---------:|:----------:|
| **x** | 0.1174 | 0.1573 | 0.7465 | 0.4767 |
| **(Intercept)** | -0.2889 | 0.9759 | -0.296 | 0.7748 |
Table: Fitting linear model: y ~ x
Cross-posting my answer to Table of multiple lm() models using apsrtable in Rmarkdown:
It can be done in a pdf_document with apsrtable and also stargazer, which additionally supports HTML.
---
title: "stargazer"
author: "hplieninger"
date: "3 August 2018"
output: pdf_document
header-includes:
- \usepackage{dcolumn}
---
```{r}
m1 <- lm(Fertility ~ Education , data = swiss)
m2 <- lm(Fertility ~ Education + Agriculture, data = swiss)
m3 <- lm(Fertility ~ . , data = swiss)
```
```{r, results='asis'}
apsrtable::apsrtable(m1, m2, m3, Sweave = TRUE)
```
```{r, results='asis'}
# If output: pdf_document
stargazer::stargazer(m1, m2, m3)
# If output: html_document
# stargazer::stargazer(m1, m2, m3, type = "html")
```
Related
module Digits
type Digit = Unison | Semitone | Tone | MinorThird | MajorThird | PerfectFourth | AugmentedFourth | PerfectFifth | MinorSixth | MajorSixth | MinorSeventh | MajorSeventh type 'd GeneralizedDigit = SmallDigit of 'd | Octave type 't Number = EmptyNumber | CountedNumber of 't * 't Number
let swapOctave: Digit GeneralizedDigit -> Digit GeneralizedDigit = fun x -> match x with SmallDigit Unison -> Octave | Octave -> SmallDigit Unison | g -> g
let limitLength: 'r Number -> Digit = fun a -> match a with EmptyNumber -> Unison | CountedNumber(_,EmptyNumber) -> Semitone | CountedNumber(_,CountedNumber(_,EmptyNumber)) -> Tone | CountedNumber(_,CountedNumber(_,CountedNumber(_,EmptyNumber))) -> MinorThird | _ -> MajorSeventh
In F# I can put multiple type definitions on the same line without semicolons without any problems, but when I remove the newline between the let statements I get the error FS0010. I know that in Haskell statements can be separated by a single semicolon but in F# neither a single semicolon nor a double semicolon will work. How do I have multiple let statements on the same line?
You can do this with the let .. in syntax like so:
let f () = let a = 1 in let b = 2 in a + b
f () // gives 3 as a result
But I would really recommend against doing multiple single-line definitions like this. It's hard for people to read.
If you want multiple let bindings to bound values to variables, then you also can use the "tuple syntax".
let x,y,z = 1, "Hi", 3.0
As explained by Phillip, the let .. in .. construct allows you to define a local variable as part of a one-line expression.
However, your example seems to be trying to define multiple top-level definitions in a module, which is something you cannot achieve with let .. in ...
As far as I can tell, you can actually do this by separating the definitions with two semicolons, i.e. ;;. If I save the following as test.fs and load it using #load, I get no errors:
module Digits
type Digit = Unison | Semitone | Tone | MinorThird | MajorThird | PerfectFourth | AugmentedFourth | PerfectFifth | MinorSixth | MajorSixth | MinorSeventh | MajorSeventh type 'd GeneralizedDigit = SmallDigit of 'd | Octave type 't Number = EmptyNumber | CountedNumber of 't * 't Number
let swapOctave: Digit GeneralizedDigit -> Digit GeneralizedDigit = fun x -> match x with SmallDigit Unison -> Octave | Octave -> SmallDigit Unison | g -> g;; let limitLength: 'r Number -> Digit = fun a -> match a with EmptyNumber -> Unison | CountedNumber(_,EmptyNumber) -> Semitone | CountedNumber(_,CountedNumber(_,EmptyNumber)) -> Tone | CountedNumber(_,CountedNumber(_,CountedNumber(_,EmptyNumber))) -> MinorThird | _ -> MajorSeventh
I tested this in F# 5.0. It may be the case that this has changed in F# 6 which removed deprecated features like #light "off". The removal of ;; is not discussed in the post, but it may have been a related change. If that is the case, you may report it as a regression - but it is likely support for ;; should also be removed!
As mentioned by Phillip, I do not see any reason for actually trying to do this.
Is there a way to reshape the data in pig?
The data looks like this -
id | p1 | count
1 | "Accessory" | 3
1 | "clothing" | 2
2 | "Books" | 1
I want to reshape the data so that the output would look like this--
id | Accessory | clothing | Books
1 | 3 | 2 | 0
2 | 0 | 0 | 1
Can anyone please suggest some way around?
If its a fixed set of product line the below code might help, otherwise you can go for a custom UDF which helps in achieving the objective.
Input : a.csv
1|Accessory|3
1|Clothing|2
2|Books|1
Pig Snippet :
test = LOAD 'a.csv' USING PigStorage('|') AS (product_id:long,product_name:chararray,rec_cnt:long);
req_stats = FOREACH (GROUP test BY product_id) {
accessory = FILTER test BY product_name=='Accessory';
clothing = FILTER test BY product_name=='Clothing';
books = FILTER test BY product_name=='Books';
GENERATE group AS product_id, (IsEmpty(accessory) ? '0' : BagToString(accessory.rec_cnt)) AS a_cnt, (IsEmpty(clothing) ? '0' : BagToString(clothing.rec_cnt)) AS c_cnt, (IsEmpty(books) ? '0' : BagToString(books.rec_cnt)) AS b_cnt;
};
DUMP req_stats;
Output :DUMP req_stats;
(1,3,2,0)
(2,0,0,1)
I am trying to use NLTK package to capture the following chunk in a sentence:
verb + smth + noun
or it may be
verb + smth + noun + and + noun
I truthfully spent entire day messing with regex, but still nothing proper is produced..
I was looking at this tutorial which wasn't much of help.
When you have an idea of what those somethings that might come in between are, there is a relatively easy method using NLTK's CFG. This is most certainly not the most efficient way. For a comprehensive analysis, consult NLTK's book on chapter 8.
We have two patterns as you mentioned:
<verb> ... <noun>
<verb> ... <noun> "and" <noun>
We should assemble a list of VPs and NPs and also the range of possible words that could happen in between. As a silly little example:
grammar = nltk.CFG.fromstring("""
% start S
S -> VP SOMETHING NP
VP -> V
SOMETHING -> WORDS SOMETHING
SOMETHING ->
NP -> N 'and' N
NP -> N
V -> 'told' | 'scolded' | 'loved' | 'respected' | 'nominated' | 'rescued' | 'included'
N -> 'this' | 'us' | 'them' | 'you' | 'I' | 'me' | 'him'|'her'
WORDS -> 'among' | 'others' | 'not' | 'all' | 'of'| 'uhm' | '...' | 'let'| 'finish' | 'certainly' | 'maybe' | 'even' | 'me'
""")
Now suppose this is the list of the sentences we want to use our filter against:
sentences = ['scolded me and you', 'included certainly uhm maybe even her and I', 'loved me and maybe many others','nominated others not even him', 'told certainly among others uhm let me finish ... us and them', 'rescued all of us','rescued me and somebody else']
As you can see, the third and the last phrases don't pass the filter. We can check whether the rest match the pattern:
def sentence_filter(sent, grammar):
rd_parser = nltk.RecursiveDescentParser(grammar)
try:
for p in rd_parser.parse(sent):
print("SUCCESS!")
except:
print("Doesn't match the filter...")
for s in sentences:
s = s.split()
sentence_filter(s, grammar)
When we run this, we get this result:
>>>
SUCCESS!
SUCCESS!
Doesn't match the filter...
SUCCESS!
SUCCESS!
SUCCESS!
Doesn't match the filter...
>>>
DOORS Version: 9.5.2.1
I'll try to break this down as simple as I can. First, I'll start with the data. Assume I have a module, Module, in DOORS. Module is comprised of:
Tree Structure
Assume that Object Text for headings and sub-headings are blank, and assume Object Text for the remaining Level 3 objects is the same as the name of the object itself. For example, Object Heading is blank for Object_1.1.0-1, but its Object Text is "Object_1.1.0-1".
- Module
- 1 Heading1 // Object Heading: "Heading1" ; Object Number: 1
| - 1.1 Sub-Heading1.1 // Object Heading: "Sub-Heading1.1" ; Object Number: 1.1
| | + Object_1.1.0-1 // Object Heading: "" ; Object Number: 1.1.0-1
| | + Object_1.1.0-2 // Object Heading: "" ; Object Number: 1.1.0-2
| | | .
| | | .
| | | .
| | + Object_1.1.0-A // Object Heading: "" ; Object Number: 1.1.0-A
| |
| - 1.2 Sub-Heading1.2 // Object Heading: "Sub-Heading1.2" ; Object Number: 1.2
| + Object_1.2.0-1 // Object Heading: "" ; Object Number: 1.2.0-1
| + Object_1.2.0-2 // Object Heading: "" ; Object Number: 1.2.0-2
| | .
| | .
| | .
| + Object_1.2.0-B // Object Heading: "" ; Object Number: 1.2.0-B
|
- 2 Heading2 // Object Heading: "Heading2" ; Object Number: 2
- 2.1 Sub-Heading2.1 // Object Heading: "Sub-Heading2.1" ; Object Number: 2.1
| + Object_2.1.0-1 // Object Heading: "" ; Object Number: 2.1.0-1
| + Object_2.1.0-2 // Object Heading: "" ; Object Number: 2.1.0-2
| | .
| | .
| | .
| + Object_2.1.0-C // Object Heading: "" ; Object Number: 2.1.0-C
|
- 2.2 Sub-Heading2.1 // Object Heading: "Sub-Heading2.1" ; Object Number 2.2
+ Object_2.2.0-1 // Object Heading: "" ; Object Number: 2.2.0-1
+ Object_2.2.0-2 // Object Heading: "" ; Object Number: 2.2.0-2
| .
| .
| .
+ Object_2.2.0-D // Object Heading: "" ; Object Number: 2.2.0-D
And so on and so forth . . .
Attributes
*Object Heading and Text*, Version, Data
Object Heading and Text seems to be a DOORS thing, so I won't explain that here. Data here is generic (and, in reality, represents more than one attribute). Some data is applicable to some versions while other data is applicable to other versions. The data for different versions may intersect while some data for other versions are mutually exclusive. Version is a single string that delimits the different versions by new lines, "\n". So, let's assume that Version is:
v1\nv2\nv3 . . . v\nvX
or, in a more readable format:
v1
v2
v3
.
.
.
vX
What's more, Version for one object may be (comma-separated here for readability) v1, v2, v3, . . ., vX while for another it might be v1, v3 and for another perhaps just v2. Any combination of available versions, really.
The Problem
What I'm attempting to do seems to me like it should be easy. A no-brainer. Just to pick an example, let's say I want to apply a filter whereby I view only Sub-Heading1.2 and its children, and that only for Version v3. I've tried many variations on the theme, but I can only seem to accomplish one or the other. Either I successfully isolate data for a single section or a single version, but I cannot get both. When I apply a filter for a single section, say Sub-Heading1.2 and its children, and then AND that with "includes v3"; I will get that section, but it refuses to show only that section only for v3.
In any programming language, a and b and c evaluates to true IF AND ONLY IF a and b and c. What I'm seeing in DOORS seems to me to be more like (a and b) or c.
With a DOORS database described as above, how can I view only the objects in a given range (or an object and its descendants) only for a given version? I know DXL exists as a potential solution, but a GUI solution is preferable.
Your issue is Include Descendants. This options specifically ignores the filter. What it is really saying is, "Show me everything that matches my filter, and all of their descendants".
Using your example above, what you want for a filter is:
Object Number >= 1.2
and
Object Number < 2 (or maybe 1.3 depending on how you want it)
and
Version includes v3
This will give you what you are looking for. Be sure NOT to Include Descendants as this will negate the second rule in the filter.
Good luck!
If i have a table in a WebFocus Raport design
+--------+---------+--------+---------+
| left_1 | right_1 | left_2 | right_2 |
+--------+---------+--------+---------+
| v11 | p11 | v21 | v21 |
+--------+---------+--------+---------+
| v12 | p12 | v22 | v22 |
....
How to do a such table with syllabus column titles:
+-------+-------+-------+-------+
| One | Two |
+-------+-------+-------+-------+
| left | right | left | right |
+-------+-------+-------+-------+
| v11 | p11 | v21 | v21 |
+-------+-------+-------+-------+
| v12 | p12 | v22 | v22 |
....
Thank you
Sorry for the delay of the answer :)
To rename columns, with the AS command. Example:
TABLE FILE SYSTABLE
PRINT NAME
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
END
To put the heading columns, you can work with the ACROSS command but it will be more tricky that if u use simply SUBHEAD. With the same example:
TABLE FILE SYSTABLE
PRINT NAME NOPRINT
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
ON TABLE SUBHEAD
"<+0>One<+0> Two"
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
UNITS=IN, PAGESIZE='Letter',
LEFTMARGIN=0.500000, RIGHTMARGIN=0.500000,
TOPMARGIN=0.500000, BOTTOMMARGIN=0.500000,
SQUEEZE=ON, GRID=OFF, ORIENTATION=LANDSCAPE, $
TYPE=REPORT,FONT='ARIAL',SIZE=9,$
TYPE=TABHEADING,HEADALIGN=BODY,$
TYPE=TABHEADING, LINE=1, ITEM=1, COLSPAN=2, SQUEEZE=ON,$
TYPE=TABHEADING, LINE=1, ITEM=2, COLSPAN=2, SQUEEZE=ON,$
ENDSTYLE
END
Hope it helps!
I'm not entirely sure if you load the headers as a field or if that is the field name
But this might help you
Define fields
TITL1/A3 = 'One';
TITL2/A3 = 'Two';
BLANK/A1 = '';
Edit the Left and Right title fields to remove the _1 or _2
Print the fields BY BLANK NOPRINT
Add
ON BLANK SUBHEAD
"
You can also add more rows to the subhead if you need more titles
You can easily do it by embedding HTML/CSS scripts in report(.fex) file.
just add the HTML/css code at the end of the file.
For eg.
-HTMLFORM BEGIN // to start styling your generated report table with HTML/CSS
TABLE tr
td:first-child // applies on 1st row ONLY.It can be td or th.
{
colspan = "2"; //to merge 2 columns
}
-HTMLFORM END //end HTML.
So the first row must have two cells having title "ONE" and "TWO"(in your case), and both cells must have property of colspan = "2"
Also you can refer:
Colspan propery from here
manipulating first row of table from here
Second option is to write the whole code in a file and save it in .htm/.html format and just insert the file in to WEBFOCUS(.fex) file.For eg.
-HTMLFORM BEGIN
-INCLUDE HTML_FILE.HTML
-HTMLFORM END
Hope it helps.Thanks.