因此,如标题中所述,我有两个数据集:
数据1:
structure(list(Name = structure(c(18L, 19L, 5L, 13L, 14L, 31L ), .Label = c("AMC Javelin", "Cadillac Fleetwood", "Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger", "Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L", "Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental", "Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag", "Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2", "Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"), class = "factor"), mpg = c(145, 120, 150, 132, 110, 98), cyl = c(93, 116, 114, 156, 148, 167), disp = c(160, 160, 108, 258, 360, 225), hp = c(110, 110, 93, 110, 175, 105)), .Names = c("Name", "mpg", "cyl", "disp", "hp"), row.names = c(NA, 6L), class = "data.frame")
数据2:
structure(list(Name = structure(c(18L, 19L, 5L, 13L, 14L, 31L ), .Label = c("AMC Javelin", "Cadillac Fleetwood", "Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger", "Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L", "Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental", "Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag", "Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2", "Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"), class = "factor"), mpg_1 = c(125, 133, 143, 141, 134, 238), cyl_1 = c(114, 153, 112, 136, 128, 155), disp_1 = c(113, 143, 144, 131, 431, 331), hp_1 = c(332, 221, 113, 331, 134, 151)), .Names = c("Name", "mpg_1", "cyl_1", "disp_1", "hp_1"), row.names = c(NA, 6L), class = "data.frame")
我想计算数据集中相应行之间的比率.行(4列)中的所有值都应该用于比率计算,并且应该在数据集之间计算比率.使用更简单的解释:
data1[1,2] / data2[1,2] data1[1,2] / data2[1,3] ... data1[1,3] / data2[1,2] ...
我想将结果存储在单独的数据中,并且标记的列很容易识别比率的计算方式.