这应该很简单吧?
所以我有一个有效的自定义函数。我可以输入数据框的名称 (crick) 以及我想要在其中运行的试验,例如 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)
}
我想使用每行中的数字2 个特定列(与函数变量同名)作为函数中的输入。每个crick
都伴随着一个特定的试验
,正如您从数据此处
函数speed.hd1
给出由hd1指定的特定速度速度和时间在此数据集中 bc每个crick速度数据存储在不同的文件中(正如您从第二个链接中看到的那样)我必须在speed中指定crick .hd1
函数的结果
,我想在数据框中创建一个新列,其中包含我尝试过的
crick.trial.sv$speed <- speed.hd1(crick.trial.sv$crick, crick.trial.sv$trial)
,并且
crick.trial.sv$speed <- speed.hd1(crick.trial.sv[1:25,3], crick.trial.sv[1:25,4])
给出错误:$运算符对于原子向量无效
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
发布评论