私はステーションの名前に基づいてデータフレームのリストを持っている大量のデータセットを持っており、行のチェックアウト名とリターン名に基づいて数値で新しい列を作成したいと考えています。データのサンプルを以下に示します。ReturnKioskNameはその後、カウント値が0でなければなりませんよう特定のデータフレーム内の値に応じて、データフレームのリスト内に新しい列を作成するにはどうすればよいですか?
fz$'66th & Center'
Bike CheckoutKioskName ReturnKioskName
24583 191 66th & Center 66th & Center
24584 191 66th & Center 66th & Center
24585 191 66th & Center 66th & Center
24586 191 66th & Center 66th & Center
24587 191 66th & Center 66th & Center
24588 191 66th & Center 66th & Center
24589 11 66th & Center 66th & Center
24590 11 66th & Center 66th & Center
24591 11 66th & Center 66th & Center
24592 11 66th & Center 66th & Center'
私は、CheckoutKioskNameが同じであれば「に基づいて、カウント」という名前の新しい列を作成したいCheckoutKioskNameのISN」の場合リストの値の名前(この場合は '66th & Center')と同じでなければなりません。最後のオプションは、ReturnKioskNameがリストの値の名前と同じでない場合、カウント値はこれを行う私の試みは、if elseステートメントの下にあります。私は、列が要素であるとき、または列が文字であるときのどちらかを使用するとき、エラーが発生し続ける。
if(test$CheckoutKioskName == test$ReturnKioskName){
test$count <- 0
}else{
if(test$ReturnKioskName != t){
test$count <- -1
}else{
if(test$CheckoutKioskName != t){
test$count <- 1
}
}
}
私は、このタスクを完了するためにlapply使用する方法があると思いたいが、私はここにそれを使用するたびに失敗し続けています。
私は何か助けていただきありがとうございます。
私はこれを動作させることはできません。それは私に各データフレームの長さを扱うエラーを与える。 – Brett
@Brettコードに 'test $ ReturnKioskName'という誤字がありました。今は修正されています。 – akrun
それは今完璧に動作します!ありがとうございました。 – Brett