In my opinion this is one of the R stuff which is annoying. Some stuff is not logic or at least intuitively doable.
Now in this post, the usage of greek symbols in corrplot was nicely explained. However what I can't get running is the other way around with first a greek letter and than normal text. E.g.
colnames(data_matrix)[2] <- c(":Delta")
or
colnames(data_matrix)[2] <- c("=S1P[Delta]")
are working fine.
However putting the Delta BEFORE the text is not working for me. Any suggestion on this?
After playing around I found this solution:
colnames(data_mat)[2] <- c(":Delta [S1P]") so its logical and simple after all.
Now, one remaining problem is an empty space. I can write colnames(data_mat)[2] <- c(":Delta [S1P]") but not colnames(data_mat)[2] <- c(":Delta [S 1P]")
Any suggestions on this particular problem?
Related
I am pretty green when it comes to R and coding in general. I've been working on a CS project recently for a linguistics course through which I'm finding the words that surround various natural landscape words in The Lord of the Rings. For instance, I'm interested in finding the descriptive words used around words like "stream", "mountain", etc.
Anyhow, to extract all of these words from the text, I've been working off of this post. When running this command by itself, it works:
stringr::str_extract_all(text, "([^\\s]+\\s){4}stream(\\s[^\\s]+){6}")
where "stream" is the specific word I'm going after. The numbers before and after specify how many words before and after I want to extract along with it.
However, I'm interested in combining this (and some other things) into a single function, where all you need to plug in the text you want to search, and the word you want to get context for. However, as far as I've tinkered, I can't get anything other than a specific word to work in the above code. Would there be a way to, in the context of writing a function in R, include the above code, but with a variable input, for instance
stringr::str_extract_all(text, "([^\\s]+\\s){4}WORD(\\s[^\\s]+){6}")
where WORD is whatever you specify in the overall function:
function(text,WORD)
I apologize for the generally apparent newb-ness of this post. I am very new to all of this but would greatly appreciate any help you could offer.
This is what you are looking for, if I understood you correctly,
my_fun <- function(input_text, word) {
stringr::str_extract_all(
string = input_text,
pattern = paste("([^\\s]+\\s){4}", word, "(\\s[^\\s]+){6}", sep = "")
)
}
May the light of EƤrendil ever shine upon you!
I have this code:
(%i3)depends([y,x],t)$
eqsp: [y=2*x,
v=diff(y,t,1)+y];
eliminate(eqsp,[y]);
(eqsp) [y=2*x,v='diff(y,t,1)+y]
(%o3) [-'diff(y,t,1)-2*x+v]
And this is a picture for better visualization:
PNG of code in wxMaxima
I was expecting that Maxima would perform a substitution of "y" in the second equation, and then differentiate to get "[-2*diff(x,t,1)-2*x+v]".
This is of course not the real problem (which has many more equations), it's just that I think I'm missing some concept here for Maxima to do what I want.
Thanks in advance for your comments. I'm a newbie in Stackoverflow and in Maxima, sorry if I made some mistake.
I'm trying to assign the result of a chain matrix multiplication in Maxima to a new variable. I'm not sure as a new user why line %o6 isn't the same as the previous and fully evaluate the chain. Also why when I enter the new variable name "B" I simply have "B" returned back to me and not ([32, 32], [32, 32]). Basic questions I know but I've searched the documentation for a number of hours, and tutorials, and the syntax that I'm supposed to use here to get what I guess I was expecting as output, is still unclear to me.
I can't tell for sure, but it appears that the problem is that B : A.A.A is entered holding the shift key for at least one of the spaces, and Shift+Space is interpreted as non-breaking space instead of ordinary space. This appears to be a known bug or at least a serious misfeature in wxMaxima; see: https://github.com/wxMaxima-developers/wxmaxima/issues/1031
(I say misfeature because Shift+Space --> non-breaking space is documented in the wxMaxima documentation, but it seems like a classic example of "bad affordance"; it is all too easy to do the wrong thing without knowing it. Anyway this is just my opinion.)
I built wxMaxima from current source code and it appears that Shift+Space is now not interpreted as non-breaking space in code, so B : A.A.A should have the expected effect even if shift key is held while typing space. The current version is 19.07.0-DevelopmentSnapshot. I poked through the commit log a bit, but I can't figure out which commit changed the behavior of Shift+Space, so it's possible that the problem is not fixed and it is just fortuitous that I am not encountering it.
There are two workarounds, if one doesn't want to hazard an upgrade. (1) Omit spaces. (2) Be careful to only type space without shift.
Hope this is helpful in some way.
The background to this is that I'm mostly a Python programmer who has some passing familiarity with R. I've been tasked to look at an R script that was written by a Perl programmer who used for and while loops a lot, to see if I can make it more R-like and get it to run faster.
For example purposes, I have the following list:
> lnums <- list(1:5, 6:7, 8:12)
For the elements that have a length less than 5 (lnums[[2]]), I want to change the length to be 5. The original code uses a for loop to tack NA values to the end of any shorter vectors, and I know that there's got to be a better way than that. I was playing around with ways to get to it and came up with
> sapply(lnums, FUN=function(x) length(x) < 5)
which gets the right element, but I'm unable to figure out how to incorporate this into the subscript of a length(lnums[]) <- 5 statement. I know this is probably a really novice question, but I'd appreciate any help I can get.
Additionally, the reason that I want to increase the length of the shorter list elements is so that I can put the list into a data frame. It would be great if there was a way to do that without messing around with lengths, although I still wouldn't mind an answer to my first question to satisfy my curiosity if nothing else.
Thanks all. I've been digging through some topics in here and you've already helped me out quite a bit!
Here's one way:
lapply(lnums, 'length<-', 5)
This question feels like it should have a straightforward answer but I can't seem to figure it out, and for the first time, I can't find someone else who has already asked and gotten an answer to this question on the internet.
I have a plot title that has a greek letter (not a problem) as well as a line break (also not usually a problem). But somehow, I can't get them both to work at the same time in a single plot title.
This code works fine, except that it's too long:
title1=expression(paste("Interannual variability in "*delta^13*"C ratios in fish samples"))
plot(1,1, main=title1)
This code also works fine, and inserts the line break, but it doesn't have the greek letter or the superscript:
title1=expression(paste("Interannual variability in d13C ratios \nin fish samples"))
plot(1,1, main=title1)
But this code puts the "C ratios" on the previous line. It's so confusing.
title1=expression(paste("Interannual variability in "*delta^13*"C ratios\nin fish samples"))
plot(1,1, main=title1)
I've tried various permutations of expression, paste, and substitute but must admit that my grasp of the exact working of those functions does is patchy. My apologies if I could have found the answer in a different way.
Any thoughts would be most welcome.
Thanks!
Have you considered the atop function? (As you have discovered the "\n" character is not accepted by plotmath.)
title1=expression(atop(Interannual~variability~"in"~delta^13~C~ratios,
"in"~fish~samples))
plot(1,1, main=title1)
The only thing that needs to be quoted is the "in" since it is a reserved word.
(Regarding where to find prior discussions, there should have been hits on this topic in the r-help archives.)
require(fortunes)
fortune("Liaw-Baron principle")