Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
列aとbを持つデータフレームxがあります。値が a/b である新しい列 c が必要です。使ってきました
x = read.csv(<file>,header=TRUE) f <- function(...){ x$c = x$a / x$b } x = apply(x,1,f)
これはデータフレームを台無しにするので、これは完全に間違っていると思います。特定の時点で適用が呼び出される行の値にアクセスするにはどうすればよいですか?
を使用する必要はありませんapply。これらの操作は、ベクトルに対して完全に正常に機能します。
apply
x$c <- x$a / x$b
それ自体でうまく機能します。
詳細については、 をご覧ください?'/'。
?'/'