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