Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. structure(list(Tattoo.MUM = structure(c(1L, 1L, 1L, 2L, 2L, 2L
  2. ), .Label = c("1004", "1007", "1011", "1013", "1024", "1027",
  3. "1031", "1033", "1034", "10454", "1045A", "1045X", "1057", "1063",
  4. "1064", "1137", "114", "1155", "1168", "1177", "1178", "1187",
  5. "1194", "1195", "120", "1204", "1207", "121", "1210", "1214",
  6. "1215", "1217", "1218", "1227", "1230", "1234", "12392", "1240",
  7. "1247", "1249", "1251", "1257", "126", "1273", "1275", "1282",
  8. "1285", "1299", "1300", "1310", "1313", "1314", "1337", "134",
  9. "1365", "140", "1427", "1437", "144", "1495", "150", "154", "156",
  10. "158", "1582", "1601", "163", "166", "168", "170", "172", "174",
  11. "175", "180", "183", "19", "190", "197", "198", "199", "20",
  12. "213", "214", "217", "22", "220", "221", "225", "226", "227",
  13. "230", "231", "241", "244", "245", "248", "249", "250", "253",
  14. "264", "27", "276", "277", "278", "279", "284", "286", "29",
  15. "297", "299", "301", "305", "311", "315", "322", "336", "338",
  16. "351", "353", "354", "369", "380", "382", "385", "390", "395",
  17. "397", "399", "400", "406", "407", "409", "41", "417", "42",
  18. "424X", "426", "42A", "43", "435", "453", "455F", "461", "465",
  19. "467", "47", "487", "49", "491F", "492", "507F", "513", "522",
  20. "53", "534", "551", "553", "554", "562", "564", "566", "569",
  21. "580", "59", "5943", "60", "62", "626", "63", "639", "643", "646",
  22. "65W", "67", "68", "685", "695", "699", "700", "713", "721",
  23. "730", "731", "732", "746", "75", "751", "753", "754", "760",
  24. "765", "767", "770", "771", "773", "774", "782", "789", "790",
  25. "792", "795", "797", "809", "819", "825", "828", "837", "838F",
  26. "83X", "84", "840", "840A", "841", "842", "843", "845", "854",
  27. "856", "858", "859", "86", "869", "872", "88", "883", "885",
  28. "887", "894", "895", "896", "8F", "904", "910", "911", "912",
  29. "918", "92", "929", "930", "933", "937", "945", "951", "959",
  30. "963", "971", "972", "973", "977", "979", "987", "ANN", "D"), class = "factor"),
  31. YrBIRTH.CUBS = c(2007, 2008, 2009, 2008, 2009, 2010), Offspring = c(2,
  32. 1, 1, 2, 1, 1), YOB2 = c(2008, 2009, 2010, 2009, 2010, 2011
  33. )), .Names = c("Tattoo.MUM", "YrBIRTH.CUBS", "Offspring",
  34. "YOB2"), row.names = c(NA, 6L), class = "data.frame")
  35.  
  36. for (i in 1:(nrow(mumCounts)-1))
  37. {mumCounts$YOB2 <- mumCounts$YrBIRTH.CUBS + 1 #new column with year of birth +1 to check whether there are missing years
  38. mumCounts <- mumCounts[order(mumCounts$Tattoo.MUM, mumCounts$YrBIRTH.CUBS),]
  39. {if(mumCounts[i,'Tattoo.MUM']==mumCounts[i+1,'Tattoo.MUM'] && mumCounts[i,'YOB2']!=mumCounts[i+1,'YrBIRTH.CUBS'])
  40. {
  41. mumCountsnewRow<-c(mumCounts[i,'Tattoo.MUM'],mumCounts[i,'YOB2'],0) #create new row with the missing year
  42. mumCounts <- mumCounts[ ,1:3] #arranging dataset so that I keep only columns I need
  43. mumCounts <- rbind(mumCounts, mumCountsnewRow) #add new row to dataset
  44. colnames(mumCounts) <- c("Tattoo.MUM", "YrBIRTH.CUBS", "Offspring")
  45. mumCounts <- mumCounts[order(mumCounts$Tattoo.MUM, mumCounts$YrBIRTH.CUBS),]
  46. }
  47. }
  48. }
  49.  
  50. Warning messages:
  51. 1: In `[<-.factor`(`*tmp*`, ri, value = 4) :
  52. invalid factor level, NA generated
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement