Showing numbers without scientific notation in R - r

I need to show the following table in Markdown:
resumen<-data.frame(dato=c('cant_cli','debit', 'costo_real',
'comis_max', 'pagos', 'comis_real',
'recupero%'),
valor=
c(nrow(ops), sum(ops$Debit),sum(ops$costo_real),
sum(ops$comision_max), sum(ops$Amount), sum(ops$comision_ganada),
sum(ops$Amount)/sum(ops$Debit)
))
The result is:
dato valor
1 cant_cli 6.217400e+04
2 debit 3.943952e+06
3 costo_real 2.641091e+04
4 comis_max 1.021484e+05
5 pagos 2.003838e+06
6 comis_real 5.189941e+04
7 recupero% 5.080788e-01
But I need to have the following format:
dato valor
cant_cli 62174
debit 3943952
costo_real 26411
comis_max 102148
pagos 2003838
comis_real 51899
recupero% 50.80%
How can I make the code use this format?

Try this
as.numeric(resumen[,2])

Related

Tables in RMarkdown: not using dataframe and/or data.table

I'm having some issues trying to insert a table code in a text on RMarkdown.
Reading rmakdown cheat sheet (write with markdown) and following the instructions, my code is like this:
Palavra-chave
Biblioteca do Conhecimento Online]
Google acadêmico Portugal
Resultado encontrado
estilos de uso del espacio virtual
2
10
12
estilos de uso do espaço virtual
6
15
21
questionário estilos de uso do espaço virtual
1
5
6
Total
9
30
39
Unfortunately, in any rendering format (pdf, .docx, or HTML) table is not displayed right formatted...
Any thoughts?
Tks in advance!

Extract date from a text document in R

I am again here with an interesting problem.
I have a document like shown below:
"""UDAYA FILLING STATION ps\na MATTUPATTY ROAD oe\noe 4 MUNNAR Be:\nSeat 4 04865230318 Rat\nBree 4 ORIGINAL bepas e\n\noe: Han Die MC DE ER DC I se ek OO UO a Be ten\" % aot\n: ag 29-MAY-2019 14:02:23 [i\n— INVOICE NO: 292 hee fos\nae VEHICLE NO: NOT ENTERED Bea\nss NOZZLE NO : 1 ome\n- PRODUCT: PETROL ae\ne RATE : 75.01 INR/Ltr yee\n“| VOLUME: 1.33 Ltr ae\n~ 9 =6AMOUNT: 100.00 INR mae wae\nage, Ee pel Di EE I EE oe NE BE DO DC DE a De ee De ae Cate\notome S.1T. No : 27430268741C =. ver\nnes M.S.T. No: 27430268741V ae\n\nThank You! Visit Again\n""""
From the above document, I need to extract date highlighted in bold and Italics.
I tried with strpdate function but did not get the desired results.
Any help will be greatly appreciated.
Thanks in advance.
Assuming you only want to capture a single date, you may use sub here:
text <- "UDAYA FILLING STATION ps\na MATTUPATTY ROAD oe\noe 4 MUNNAR Be:\nSeat 4 04865230318 Rat\nBree 4 ORIGINAL bepas e\n\noe: Han Die MC DE ER DC I se ek OO UO a Be ten\" % aot\n: ag 29-MAY-2019 14:02:23 [i\n— INVOICE NO: 292 hee fos\nae VEHICLE NO: NOT ENTERED Bea\nss NOZZLE NO : 1 ome\n- PRODUCT: PETROL ae\ne RATE : 75.01 INR/Ltr yee\n“| VOLUME: 1.33 Ltr ae\n~ 9 =6AMOUNT: 100.00 INR mae wae\nage, Ee pel Di EE I EE oe NE BE DO DC DE a De ee De ae Cate\notome S.1T. No : 27430268741C =. ver\nnes M.S.T. No: 27430268741V ae\n\nThank You! Visit Again\n"
date <- sub("^.*\\b(\\d{2}-[A-Z]+-\\d{4})\\b.*", "\\1", text)
date
[1] "29-MAY-2019"
If you had the need to match multiple such dates in your text, then you may use regmatches along with regexec:
text <- "Hello World 29-MAY-2019 Goodbye World 01-JAN-2018"
regmatches(text,regexec("\\b(\\d{2}-[A-Z]+-\\d{4})\\b", text))[[1]]
[1] "29-MAY-2019" "29-MAY-2019"

extract number in string using regex

I have a data.frame like this :
SO <- data.frame(coiffure_IDF$SIREN, coiffure_IDF$L6_NORMALISEE )
coiffure_IDF.SIREN coiffure_IDF.L6_NORMALISEE
1 54805015 75008 PARIS
2 300086907 94210 ST MAUR DES FOSSES
3 300090453 94220 CHARENTON LE PONT
4 300209608 75007 PARIS
5 300570553 95880 ENGHIEN LES BAINS
6 301123626 75019 PARIS
7 301362349 92300 LEVALLOIS PERRET
I want to have this :
coiffure_IDF.SIREN codpos_norm ville
1 54805015 75008 PARIS
2 300086907 94210 ST MAUR DES FOSSES
3 300090453 94220 CHARENTON LE PONT
4 300209608 75007 PARIS
5 300570553 95880 ENGHIEN LES BAINS
6 301123626 75019 PARIS
7 301362349 92300 LEVALLOIS PERRET
so I used regex :
SO2<- SO %>% extract(col="coiffure_IDF.L6_NORMALISEE", into=c("codpos_norm", "ville"), regex="(\\d+)\\s+(\\S+)")
so I have the right column is "codpos_norm" but in "ville" in line 2 I just have "ST" in stead of "ST MAUR DES FOSSES". In line 3 just "CHARENTON", etc
so I tried to add some \\s+ and \\S+ in the regex but R told me that they are to many groups and that it has to have only 2 groups.
What could I do ?
You need to match the rest of the string in Group 2, the \S construct only matches non-whitespace chars. Use .+ to match any 1+ chars up to the string end:
extract(col="coiffure_IDF.L6_NORMALISEE", into=c("codpos_norm", "ville"), regex="(\\d+)\\s+(.+)")
You may use .* to match empty strings (if there is no text after 1+ whitespaces).

Exception importing data into neo4j using batch-import

I am running neo-4j 1.8.2 on a remote unix box. I am using this jar (https://github.com/jexp/batch-import/downloads).
nodes.csv is same as given in example:
name age works_on
Michael 37 neo4j
Selina 14
Rana 6
Selma 4
rels.csv is like this:
start end type since counter:int
1 2 FATHER_OF 1998-07-10 1
1 3 FATHER_OF 2007-09-15 2
1 4 FATHER_OF 2008-05-03 3
3 4 SISTER_OF 2008-05-03 5
2 3 SISTER_OF 2007-09-15 7
But i am getting this exception :
Using Existing Configuration File
Total import time: 0 seconds
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at org.neo4j.batchimport.Importer$Data.split(Importer.java:156)
at org.neo4j.batchimport.Importer$Data.update(Importer.java:167)
at org.neo4j.batchimport.Importer.importNodes(Importer.java:226)
at org.neo4j.batchimport.Importer.main(Importer.java:83)
I am new to neo4j, was checking if this importer can save some coding effort.
It would be great if someone can point to the probable mistake.
Thanks for help!
--Edit:--
My nodes.csv
name dob city state s_id balance desc mgr_primary mgr_secondary mgr_tertiary mgr_name mgr_status
John Von 8/11/1928 Denver CO 1114-010 7.5 RA 0023-0990 0100-0110 Doozman Keith Active
my rels.csv
start end type since status f_type f_num
2 1 address_of
1 3 has_account 5 Active
4 3 f_of Primary 0111-0230
Hi I had some issues in the past with the batch import script.
The formating of your file must be very rigorous, which means :
no extra spaces where not expected, like the ones I see in the first line of your rels.csv before "start"
no multiple spaces in place of the tab. If your files are exactly like what you've copied here, you have 4 spaces instead of on tab, and this is not going to work, as the script uses a tokenizer looking for tabs !!!
I had this issue because I always convert tabs to 4 spaces, and once I understood that, I stopped doing it for my csv !

SAS: PROC SGPLOT BY GROUP auto file names

I am plotting some data using BY GROUP option. While I am able to use #byval option to automatically put BY GROUP value in title of each plot, but I want to save each plot individually and want to name it after #byval instead of calling it - SGPLOT01, SGPLOT02 ...
e.g. Lets say I have:
data xyz;
input type$ x y1 y2##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series1 x=x y=y1/markers;
series2 x=x y=y2/markers;
title "#byval";
RUN;
In this example, two plots will be created one each for type A and B. But program will automatically name them as SGPLOT1.pdf and SGPLOT2.pdf. I would rather want to name them A.pdf and B.pdf, and want to save them to directory "C:/SGPLOTS/".
Thanks for your help.
One option is to use ODS and put use a macro to print each TYPE separately, like in the following example.
data xyz;
input type$ x y1 y2 ##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;
RUN;
ods listing close;
%macro plot_it(type=);
goptions reset
device = sasprtc
target = sasprtc
;
ods pdf file="C:/SGPLOTS/&type..pdf" notoc;
PROC SGPLOT DATA=xyz;
by type;
where type = "&type";
series x=x y=y1/markers;
series x=x y=y2/markers;
title "#byval";
RUN;
ods pdf close;
%mend plot_it;
%plot_it(type=A);
%plot_it(type=B);
You want to add the variable name within parentheses, after #BYVAL. In this example you want to put #byval(type) in your title.
I have put your example within something SAS calls an "HTML sandwich," which is two lines on top and two lines on the bottom. In addition I added the helpbrowser option, which tells SAS to use its own capabilities to display the html output.
option helpbrowser=sas;
/**** top of html sandwich *****/
ods html ;
ods graphics on;
/*******************************/
data xyz;
input type$ x y1 y2##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series x=x y=y1/markers;
series x=x y=y2/markers;
title "Here is the type: #byval(type)";
RUN;
/**** bottom of html sandwich *****/
ods graphics off;
ods html close;
/**********************************/

Resources