Using a special character for figure legend - character

I need to correctly spell an Indigenous name on a figure I am developing in R.
To start, the Geography was "Nisga'a Lands". Ultimately I want it to read "Nisg̱̱a'a Lands". So, the g becomes a g with a dash below (g̱̱).
I tried simply copying and pasting this and mutating the data frame, as well as playing with the encoding:
all_income_data = as.data.frame(all_income_data) %>%
mutate(Geography = stri_enc_toutf8(Geography)) %>%
mutate(Geography = ifelse(Geography == "Nisga'a Lands", "Nisg̱̱a'a Lands", Geography))
I unfortunately was only able to produce this result:
Is it possible to get the g the way I need it? Thanks so much in advance for any help

Related

Function Corpus in Quanteda doesn't work because of a kwic objects

First of all, I'm working on a big data project which consists in analyze some press URLs to detect the most popular topics. My topic is about football (Mbappe contract) and I collected 180 URLs from Marca, a Spanish media mass, in a .txt file.
When I want to create a matrix-document with Corpus function from Quanteda package, I obtain this: Error: corpus() only works on character, corpus, Corpus, data.frame, kwic objects.
In some URLs there is a kwic object (maybe a video, adverts...) that doesn't allow me to work just with text, and I think it's because when inspecting HTML div class = body, automatically picks these kwic objects.
I leave here my code to read it:
url_marca <- read.table("mbappe.txt",stringsAsFactors = F)$V1
get_marca_text <- function(url){url %>%
read_html() %>%
html_nodes("div.ue-c-article__body") %>%
html_text() %>%
str_replace_all("[\r\n]" , "")}
text_marca_mbappe <- sapply(url_marca,get_marca_text)
Does anyone know if is it because of a mistake in html_notes when inspecting the URL or is it something different?

how to fill na with a specific value based on a condition

Still learning python, and struggling with dates and na's.. I have a situation as the image below would show
enter image description here
for the NAT values in the column EndDT_New, i would like to fill them with a specific value based on a condition, eg:
if the DATE_ACT_CLOSED = '01/01/2040' then replace just the NAT in EndDT_New with 30/03/2021 else
if the DATE_ACT_CLOSED <> '01/01/2040', then replace just the NAT in EndDT_New with the value in DATE_ACT_CLOSED .
My previous experience is in SAS, so its quite a learning curve and mind shift to python.
Any help is much appreciated.
Kind Regards,
i reckon i figured it out.
df_all_valid.loc[(np.isnat(df_all_valid['EndDT_New'])==True) & (df_all_valid['DATE_ACT_CLOSED'] == '01/01/2040'), 'EndDT_New'] = np.datetime64('2021-03-30')

Is it possible to use tbl_regression fonction with lmer fonction with random effect?

I work on antifungal activity of some molecules ("cyclo") added with fungicides and I want to assess impact of these cyclos and their concentration ratio. CMI is a quantitative variable and all other variables are factors.
I have this script:
mod=lmer(CMI ~ cyclo*ratio + (1|fungicide) + (1|strains), data)
And I'd like to know if I can use tbl_regression() (library(gtsummary)) with my lmer()?
If yes, what do I have to specify for exponentiate term ?
If I write exponentiate=FALSE I obtain the same values than the estimates in the classical summary(mod).
Thank you for your help
Steffi
The default behavior for tbl_regression() for a mixed-effects models is to print the fixed-effects only. To see the full output, including the random components, you need to override the default function for tidying up the model results using the tidy_fun= argument.
library(gtsummary)
lme4::lmer(age ~ marker + (1|grade), trial) %>%
tbl_regression(
# set the tidying function to broom.mixed::tidy to show random effects
tidy_fun = broom.mixed::tidy,
)
You can use the label= argument to update the label displayed for the random components if you wish.
The default is exponentiate = FALSE, so you don't need specify in the tbl_regression() call.
For more details on the tidy_fun= argument, you can review this help file: http://www.danieldsjoberg.com/gtsummary/reference/vetted_models.html
Hope this helps! Happy Coding!

Matlab: Update an excel sheet

I am using Matlab to read a workbook with a bunch of sheets in it.
I do some calculation and have to update one particular column in one sheet. I tried using xlswrite after xlsread, it does not work.
So, my code looks something like:
[~,~,Data] = xlsread('MyFile.xlsx', 'MySheet');
Data(2:end-1,5) = Data(2:end-1,5) + 1.5; %Random operation for illustration only
ret = xlswrite('MyFile.xlsx',Data,'MySheet');
But ret is 0. So, I am not able to achieve replacement process. Can you please help.
Thanks
Based on my own comment:
Please use the second output argument as well an check what message you get:
[status,message] = xlswrite(filename,A,sheet)
Hopefully that is sufficient to find the cause, please let us know if that's the case.
Apparently it was indeed sufficient for the asker.

Matlab: dynamic name for structure

I want to create a structure with a variable name in a matlab script. The idea is to extract a part of an input string filled by the user and to create a structure with this name. For example:
CompleteCaseName = input('s');
USER WRITES '2013-06-12_test001_blabla';
CompleteCaseName = '2013-06-12_test001_blabla'
casename(12:18) = struct('x','y','z');
In this example, casename(12:18) gives me the result test001.
I would like to do this to allow me to compare easily two cases by importing the results of each case successively. So I could write, for instance :
plot(test001.x,test001.y,test002.x,test002.y);
The problem is that the line casename(12:18) = struct('x','y','z'); is invalid for Matlab because it makes me change a string to a struct. All the examples I find with struct are based on a definition like
S = struct('x','y','z');
And I can't find a way to make a dynamical name for S based on a string.
I hope someone understood what I write :) I checked on the FAQ and with Google but I wasn't able to find the same problem.
Use a structure with a dynamic field name.
For example,
mydata.(casename(12:18)) = struct;
will give you a struct mydata with a field test001.
You can then later add your x, y, z fields to this.
You can use the fields later either by mydata.test001.x, or by mydata.(casename(12:18)).x.
If at all possible, try to stay away from using eval, as another answer suggests. It makes things very difficult to debug, and the example given there, which directly evals user input:
eval('%s = struct(''x'',''y'',''z'');',casename(12:18));
is even a security risk - what happens if the user types in a string where the selected characters are system(''rm -r /''); a? Something bad, that's what.
As I already commented, the best case scenario is when all your x and y vectors have same length. In this case you can store all data from the different files into 2 matrices and call plot(x,y) to plot each column as a series.
Alternatively, you can use a cell array such that:
c = cell(2,nufiles);
for ii = 1:numfiles
c{1,ii} = import x data from file ii
c{2,ii} = import y data from file ii
end
plot(c{:})
A structure, on the other hand
s.('test001').x = ...
s.('test001').y = ...
Use eval:
eval(sprintf('%s = struct(''x'',''y'',''z'');',casename(12:18)));
Edit: apologies, forgot the sprintf.