0

this should be simple? so I have a custom function that works. I can input the name of data frame (crick) and which trial I want to run within it for example speed.hd1(sv.j20.19, 1)

speed.hd1 <- function(crick, trial){
  hd.time <- which(crick$time == head.data$hd1[trial])
  hd.vel <- crick$velocity[hd.time]
  return(hd.vel)
}

I want to use the numbers in each row of 2 particular columns (same name as function variables) as inputs in the function . Each crick goes with a particular trial as you can see from the data here

the function speed.hd1 gives the velocity at a particular that is specified by hd1 velocity and time are in this data set here bc each crick velocity data is stored in a different file (as u see from 2nd link) I have to specify the crick in speed.hd1

and I want to make a new column in the dataframe with the results of the function

I have tried

crick.trial.sv$speed <- speed.hd1(crick.trial.sv$crick, crick.trial.sv$trial)

and

crick.trial.sv$speed <- speed.hd1(crick.trial.sv[1:25,3], crick.trial.sv[1:25,4])

which give Error: $ operator is invalid for atomic vectors

luke-od
  • 1
  • 1
  • 1
    It's difficult to understand your intent from the information you've provided. Please see here on how to create a good minimal reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jdobres Apr 03 '22 at 19:27
  • It seems like this could be simplified as a join or self-join operation, probably a one-liner. It's hard to know, however, as you shared a picture of data instead of reproducible input, you didn't share desired output, and some of the columns you use (`time` and `velocity`) aren't included in your screenshot. – Gregor Thomas Apr 03 '22 at 19:45
  • @GregorThomas I have updated with a bit of clarity of what's going on with function/data. any thought? – luke-od Apr 03 '22 at 19:59
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 03 '22 at 21:11

0 Answers0