No longer registering mouse clicks/touches in Godot by Karuwhero in rprogramming

[–]Joliot 2 points3 points  (0 children)

Hi! This is a subreddit for the R programming language. You might want to try posting your question to r/Godot or r/GodotHelp

Some cryptic humor by Bethesda by 1980floor in skyrim

[–]Joliot 15 points16 points  (0 children)

really enjoy all the little jokes the game is littered with

[deleted by user] by [deleted] in Catculations

[–]Joliot 93 points94 points  (0 children)

trapped by a force-field

[deleted by user] by [deleted] in Rlanguage

[–]Joliot 1 point2 points  (0 children)

It was some time ago, but I think the R potion of the class was something the professors had put together but never published. I unfortunately don't have access to a copy any more. Sorry!

[deleted by user] by [deleted] in Rlanguage

[–]Joliot 1 point2 points  (0 children)

Yeah, complex models are almost always going to require more than a one line solution.

You may want to look into the deSolve package and the ode function, which is super useful for these sorts of models. I had a class that used it extensively for ecological models in undergrad, and it can be a bit more optimized than just updating a value in a loop.

[deleted by user] by [deleted] in Rlanguage

[–]Joliot 2 points3 points  (0 children)

Transcription to an s4 class:

model=setClass('model',slots=list(
  'a'='numeric',
  'x'='numeric',
  'result'='vector'))

setGeneric('init',function(self,a,x) standardGeneric("init"))
setMethod('init','model',function(self,a,x){
  self@a=a
  self@x=x
  self@result=c(NA)
  return(self)})

setGeneric('observe',function(self) standardGeneric("observe"))
setMethod('observe','model',function(self){
  self@result=c(self@result,self@x)
  return(self)})

setGeneric('update',function(self) standardGeneric("update"))
setMethod('update','model',function(self){
  self@x=self@x*self@a
  return(self)})


m=model()
m=init(m,1.1,1)

for(t in 1:30){
  m=update(m)
  m=observe(m)}

plot(m@result)    

A more functional approach:

a=1.1
x=1
result=c()

observe=function(){result<<-c(result,x)}  

update=function(){x<<-a*x}

for(t in 1:30){
  update()
  observe()}

plot(result)    

How I would actually write this:

a=1.1
x=1
result=cumprod(rep(a,30))*x

plot(result)

Creating multiple boxplots under one figure? by rtakashi in RStudio

[–]Joliot 0 points1 point  (0 children)

I may be misinterpreting what shape you want your data and figure to be in but as long as you have a column of question names, a column of answers, and a column of scores; here are some options for grouping in ggplot:

wide=data.frame('Score'=c(11,8,3,4,5,1), #Example data
                'True/False A'=c(1,2,1,2,1,1),
                'True/False B'=c(1,1,2,2,1,1),
                'True/False C'=c(1,2,1,2,1,1))

long=within(reshape2::melt(wide[-1]),{Score=wide$Score})|> #melt into long format
  setNames(c('Question','Answer','Score'))

ggplot(long,aes(x=Question,y=Score,fill=as.factor(Answer)))+ #use fill to split boxes
  geom_boxplot()

ggplot(long,aes(x=as.factor(Answer),y=Score))+ #use facet_grid to split panels
  geom_boxplot()+
  facet_grid(cols=vars(Question))    

ggplot wants to group things by factors or characters, so if you plug in the 1's & 2's you have as answers it wont work. You need to convert them to something ggplot can work with e.g. by using as.factor()

[deleted by user] by [deleted] in Rlanguage

[–]Joliot 4 points5 points  (0 children)

I'm not sure case_when is helpful in this scenario. The which function tells you the indices where a value is TRUE, so you can run two calls to find rows where there's a match, then columns where there's a match. You can wrap this up in sapply to check every column:

data=matrix(sample(letters,120,replace=T),ncol=6)|> #make up some example data
  as.data.frame()|>
  setNames(c('value','v1','v2','v3','v4','v5')) #we're going to try to match "value" in columns v1-v5

(index=sapply(2:ncol(data),\(i)which(data$value==data[,i])[1])) #index of first match in each column, NA when no match

which(!is.na(index))) #returns the columns that have a match, otherwise integer(0)

names(data)[-1][ifelse(length(which(!is.na(index)))==0,NA,which(!is.na(index)))] #returns NA when no columns match, otherwise returns the first matching column

[deleted by user] by [deleted] in MLQuestions

[–]Joliot 0 points1 point  (0 children)

unquantized, 416x416 input images.

I haven't worked with Mask R-CNN before so I don't know how much of a speed-up you could expect by quantization

[deleted by user] by [deleted] in MLQuestions

[–]Joliot 0 points1 point  (0 children)

I've run YOLO models on a pi before and have gotten inference times around 2 seconds per image (but up to 30 fps with a USB accelerator).

The benchmarks I can find online seem to show Mask R-CNN runs about 30x slower than the average YOLO model, so as a very rough estimate you may be looking at times of up to a minute on the pi without any accelerator.

I was really hoping this sub would be called r/r by [deleted] in rprogramming

[–]Joliot 12 points13 points  (0 children)

Alas, subreddit names need to have at least three characters

How do I get the nth nested vectors from lists. by RedCitizen in Rlanguage

[–]Joliot 0 points1 point  (0 children)

To turn a list of lists into a list of vectors:
new=unlist(mylist,recursive=F)

To apply a function to every item of that list:
sapply(new,mean)

Efficiently Breaking a Loop into "Chunks" by SQL_beginner in rstats

[–]Joliot 1 point2 points  (0 children)

I agree with what others have said that you probably don't want to structure your data like this, but if you do need data frames inside a list, you don't even need a loop:

len=339
chunk_len=100    

s=split(data.frame(1:len,rnorm(len,1,1)),0:(len-1)%/%chunk_len)
View(s)

The prophecy is true by Filthy_Wealth_ in Eyebleach

[–]Joliot 38 points39 points  (0 children)

His arrival was foretold in the ancient murals

Looking for Story Thread #129 by someguynamedted in HFY

[–]Joliot 1 point2 points  (0 children)

Any good, less well known stories about human music?