我只是在学习R,并试图在我的数据集中总结两个vaiables。我已将Hits和Runs更改为从type factor键入numeric而不会丢失任何信息,除了4"。"应该留下的价值"。"但改为" NA"。我附上了我的代码段和数据集样本
gamestats<-read.fwf(paste0(dirdata,"Games_Plus.dat"), width= widths, col.names = colNames, na.strings = ".", stringsAsFactors = FALSE)
gamestats$Hits <- as.numeric(as.character(gamestats$Hits))
gamestats$Runs <- as.numeric(as.character(gamestats$Runs))
6-19 Peaches 8 3 Complete
6-20 Peaches 10 5 Complete
6-23 Plains 3 4 Complete
6-24 Plains 7 2 Complete
6-25 Plains 12 8 Complete
6-30 Gilroy . . No Data
7-1 Gilroy . . No Data
7-4 Sacramento 15 9 Complete
7-4 Sacramento 10 10 Complete
7-5 Sacramento 2 3 Complete