私は以下のようなデータフレームを持っており、データフレーム内の文字を条件に従って数値に置き換えて別のデータフレームを生成したいと考えています。Rデータフレーム内の文字列を数値に変更する
condition:
GD 5
O 4.5
AV 3
B 2.5
dataframe:
Name Peter Paul Mary Chan Jose
Nokia B O O GD GD
iPhone AV O O O O
Moto AV AV O O AV
HTC B O AV AV AV
dput:
structure(list(Name = c("Nokia", "iPhone", "Moto", "HTC"), Peter =
c("B", "AV", "AV", "B"), Paul = c("O", "O", "AV", "O"), Mary =
c("O", "O", "O", "AV"), Chan = c("GD", "O", "O", "AV"), Jose =
c("GD", "O", "AV", "AV")), .Names =
c("Name", "Peter", "Paul", "Mary", "Chan", "Jose"), class = "data.frame", row.names = c(NA, -4L))
desired output:
Name Peter Paul Mary Chan Jose
Nokia 2.5 4.5 4.5 5 5
iPhone 3 4.5 4.5 4.5 4.5
Moto 3 3 4.5 4.5 3
HTC 2.5 4.5 3 3 3
ありがとうございます!