R line break problem; uses commas as line breaks - r

I have used R to remove line breaks in a csv file containing text strings in one column. However, my problem is that some rows contain multiple columns when they should just have one. After a close inspection, I have found out that these columns appear when there are some types of commas in the text.
Please note that in my original dataset there are alot of break lines within a text. For example:
"I do not like apples.
Even so they are good for your eyes."
Here my aim is to remove and join them (for some reason I can't represent this example on the table below)
This is an example of the input:
| message |
| -------- |
| I love chocolate.|
| I dislike asparagus, they are not good for me.|
This is an example of the output:
| message | |
| -------- | -------------- |
| I love chocolate | |
| I dislike asparagus | they are not good for me |
I have used the str_replace_all(x, "[\r\n]" , "") function but it does not work. Can anyone help?

Related

Providing summary on data by Month in R

I have a dataset that contains information on incidents reported (either Fraud or Error). Information includes the unique ID number, date of the incident, the type of incident, the size, and whether the case is open or closed and, if closed, the closed date.
I am looking to create a script of code that will produce a new table that groups the data by month so that for each month we can see how many new incidents there have been, as well as the average size.
Additionally I would like to be able to see how many cases are open still in that month and Ideally break this down by the type of incident.
It is the counting both the new cases and the open cases that I am having the most issue with
any help would be appreciated
| Erro Type| Date of Error | ID | Size | Open/closed| Date Closed
| Fraud | 12/05/2021 | 233 | 5,000 | Open | -
| Fraud | 19/07/2020 | 194 | 23,000 | Closed | 24/01/22
| Error | 23/05/2021 | 241 | 9,000 | Open | -

Join and merge are only working partially and completely in R

I am working with a dataset that was obtained from a global environment and loaded into R. It has been saved as a CSV and is being read in R as a data frame from that CSV. This dataset (survey_df) has almost 3 million entries, I am trying to join this dataset based on a column ID (repeated multiple times since there are multiple entries per id) to what originally was a shapefile and is now loaded in R as a data frame shapefile_df . This data frame has 60,000 unique entries, each representing a geometry in a country. We expect to have many entries per geometry in most cases. I am using a simple left_join which should in theory join these two datasets together. I am running into an issue where they are not fully joining together, only some entries are. I have tried inner,fully and right join as well as merge and I keep getting the same issue. I made a full_join and a copy of the id columns to compare the ones that are not joining and I do not see any patterns. They seem to be the same id, they are not joining for some reason. I tried formatting them as.character and as.factor and yet nothing. Below I pasted a sample of the join/unjoined df.
Matched ids
| survey_df_id | survey_id_copy | shapefile_df_id
-------------- | -------------- |--------------
0901200010229 | 0901200010229 | 0901200010229
0901500010729 | 0901500010729 | 0901500010729
090050001087A | 090050001087A | 090050001087A
0900600010467 | 0900600010467 | 0900600010467
0901400010897 | 0901400010897 | 0901400010897
0901200011960 | 0901200011960 | 0901200011960
Unmatched ids
| survey_df_id | survey_id_copy | shapefile_df_id
-------------- | -------------- |--------------
01903900010480 | 01903900010480 | NA
070470001010A | NA | 070470001010A
0704700010117 | NA | 0704700010117
0704700010140 | NA | 0704700010140
0705200010672 | NA | 0705200010672
0705200010742 | NA | 0705200010742
Most of the entries that are unmatched are like the first row where shapefile_df_id is NA. However, there are a few where survey_id_copy is NA. This field is simply a mutate of survey_df_id and in theory should not be any different yet they are. Any idea what could be causing this? I suspect this is a formatting issue but as a said, using as. hasn't fixed the issue. I am using tidyverse and read.csv. Any help?

Plotting mean-values of elements with same frequencies

I have two columns in my google sheet that corresponds to 1) the frequencies of the elements and 2) their respective 'values'.
What I want is a diagram that holds the different frequencies on the x-axis, and for each frequency I want the y-axis to hold that specific frequency's value (and if there are more than one element with that frequency I want it to plot their mean value).
Two elements can share the same frequency and/or the same score, and that's why I want the mean-functionality added aswell.
If the following data would be my values:
280 6
280 4
250 2
240 1
230 3
Forgive my ascii-skills, but I'd want the graph to plot the following in that case:
^
.
.
|
| |
| |
| | |
| | | |
| | | | |
___230___240___250___260___270___280___...>
I'm not entirely familiar with Google Sheets yet and I'm not really sure how to accomplish this.
I think a pivot table should serve. Your LH column in Rows, RH in Values, with Summarise by AVERAGE. Then chart the results (select what in the image is B14:B17, Insert..., Chart and accept the first recommendation):

R markdown table with a caption

I'm trying to create a table outside of a code chunk using normal markdown notation and to add a caption to it. Here's an example file (taken from here:
---
output: pdf_document
---
| First Header | Second Header | Third Header |
| :------------ | :-----------: | -------------------: |
| First row | Data | Very long data entry |
| Second row | **Cell** | *Cell* |
| Third row | Cell that spans across two columns ||
[Table caption, works as a reference][section-mmd-tables-table1]
This unfortunately produces a rather sad string:
Removing the caption line in square brackets produces the table fine (but without the caption, obviously):
This can be achieved if I made my data into an actual data.frame and used kable as shown here but I'm looking to avoid having to do this.
The linked guide refers to MultiMarkdown, while RMarkdown uses Pandocs. Captions work a little bit differently in Pandoc. The following should do the trick. The syntax is Table: followed by your caption; Pandocs numbers automatically. Leave one line blank between the end of the table and the caption line.
---
output: pdf_document
---
| First Header | Second Header | Third Header |
| :------------ | :-----------: | -------------------: |
| First row | Data | Very long data entry |
| Second row | **Cell** | *Cell* |
| Third row | Cell that spans across two columns ||
Table: Your Caption

Selenium IDE, identify row in table based on 3 columns

I am trying to find a row in a table which contains specific values on three columns.
I have tried methods in #paul trmbrth's answer to find XPath to identify cell in table based on other column. Worked fine for 2 columns, but didn't worked with 3. I didn't find any example for cases with more than 2 values.
VEHICLE CATEGORY | CATEGORY | SUBCATEGORY
A | Exteriors | Badges
A | Exteriors | Badges
A | Exteriors | Mirrors
A | Interiors | Wheels
A | Interiors | Rears
Want cell with the combination that contains:
A | Exteriors | Mirrors
I have tried but no success:
//tr[contains(td[1], 'A')]/td[2][contains(., 'Exterior')] td[3][contains(., 'Mirror')]
//tr[contains(td[1], 'A')]/td[2][contains(., 'Exterior')] /td[3][contains(., 'Mirror')]
css=tr([td:contains('A')][td:contains('Exterior')][td:contains('Mirror')])
css=tr([td:contains('A')][td:contains('Exterior')][td:contains('Mirror')])
Can anyone help?
I think you have a couple of typos:
//tr[contains(td[1], '1') and contains(td[2], 'Eve') and contains(td[3], 'Jackson')]
But I'm not 100% this is most efficient, but it will work.

Resources