apply ステートメントを使用して、R のデータ フレームの各行に何かを実行したいと考えています。
以下は、一連のパラメーターとインデックス i を使用して関数「calc.Sphere.Metrics」を呼び出す場所で機能します。結果を各行に格納します。
for(i in 1: dim(position.matrix)[1]){
results.obs[i,] <- calc.Sphere.Metrics(i, culled.mutation.data, position.matrix, protein.metrics, radius)
}
apply、mapply ステートメントをいくつか試しましたが、うまくいきません。これを行う正しい方法は何ですか?
編集: 要求に応じて、ここに calc.Sphere.Metrics のスケルトンがあります
calc.Sphere.Metrics <- function(index, culled.mutation.data, position.matrix, protein.metrics, radius){
results <- matrix(data = 0, nrow = 1, ncol = 8)
colnames(results) <- c("Line.Length","Center", "Start","End","Positions","MutsCount","P.Value", "Within.Range")
results <- as.data.frame(results)
....
look up a bunch of stuff and fill in each column of results. All the data required is in the parameters passed in and the index.
.....
return(results)
}
Results には、top 関数の results.obs と同じ数の列があります。お役に立てれば!
ありがとう!