R Conditional Filling of Value based on Test of Existing Value - r
In brief, I have a large dataframe (~750,000 rows) most of which have a NA value in the "Age" field. I want to assign the values held in the "AcutalAge" and "InterpAge" field where the "Age" field is empty (prioritizing the "ActualAge" field first). The code snippet below is not working. Any thoughts? All of the fields are ints ranging from 0 to 150 or so.
for (r in seq_len(nrow(TreeData))){
if (is.na(TreeData[r,"Age"])){
TreeData[r,"Age"] <- TreeData[r,"ActualAge"]
}
# use InterpAge field if not a sample age tree or ActualAge tree
if (is.na(TreeData[r,"Age"])){
TreeData[r,"Age"] <- TreeData[r,"InterpAge"]
}
}
Sample Data:
"","Stand_ID","Plot_ID","StandPlot_ID","Tree_ID","District","PlotNumber","DBH","Ht","TreeStatus","Remeasurement","CrRatio","Species","Abbrev","b1","b2","b3","b4","b5","Age","Elevation","Slope","Latitude","Longitude","InterpAge","ActualSpec","ActualCD","ActualSite","ActualAge","DomSpec","Inv_Year","Disturbance","Treatment"
"1","D10P112103","R0","D10P112103R0",59,10,112103,0.551181390613437,6.23359592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"2","D10P112103","R0","D10P112103R0",58,10,112103,0.472441218773127,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"3","D10P112103","R0","D10P112103R0",30,10,112103,0.433071109386563,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"4","D10P112103","R0","D10P112103R0",7,10,112103,0.748031890613437,7.54593184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"5","D10P112103","R0","D10P112103R0",41,10,112103,0.5905515,6.88976368711472,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"6","D10P112103","R0","D10P112103R0",17,10,112103,0.472441218773127,5.24934407822132,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"7","D10P112103","R0","D10P112103R0",20,10,112103,0.157480402346641,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"8","D10P112103","R0","D10P112103R0",67,10,112103,0.354330890613437,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"9","D10P112103","R0","D10P112103R0",47,10,112103,0.393701,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"10","D10P112103","R0","D10P112103R0",16,10,112103,0.472441218773127,5.57742815644264,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"11","D10P112103","R0","D10P112103R0",57,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"12","D10P112103","R0","D10P112103R0",49,10,112103,0.669291718773127,6.88976368711472,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"13","D10P112103","R0","D10P112103R0",62,10,112103,0.393701,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"14","D10P112103","R0","D10P112103R0",36,10,112103,0.393701,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"15","D10P112103","R0","D10P112103R0",53,10,112103,0.1968505,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"16","D10P112103","R0","D10P112103R0",15,10,112103,0.354330890613437,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"17","D10P112103","R0","D10P112103R0",63,10,112103,0.157480402346641,4.26509184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"18","D10P112103","R0","D10P112103R0",43,10,112103,0.393701,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"19","D10P112103","R0","D10P112103R0",4,10,112103,0.472441218773127,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"20","D10P112103","R0","D10P112103R0",79,10,112103,0.433071109386563,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"21","D10P112103","R0","D10P112103R0",66,10,112103,0.236220609386563,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"22","D10P112103","R0","D10P112103R0",28,10,112103,0.472441218773127,6.23359592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"23","D10P112103","R0","D10P112103R0",34,10,112103,0.118110304693282,4.26509184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"24","D10P112103","R0","D10P112103R0",46,10,112103,0.236220609386563,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"25","D10P112103","R0","D10P112103R0",21,10,112103,0.669291718773127,6.23359592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"26","D10P112103","R0","D10P112103R0",81,10,112103,0.275590695306718,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"27","D10P112103","R0","D10P112103R0",77,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"28","D10P112103","R0","D10P112103R0",64,10,112103,0.157480402346641,4.26509184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"29","D10P112103","R0","D10P112103R0",72,10,112103,0.472441218773127,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"30","D10P112103","R0","D10P112103R0",73,10,112103,0.354330890613437,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"31","D10P112103","R0","D10P112103R0",55,10,112103,0.1968505,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"32","D10P112103","R0","D10P112103R0",32,10,112103,1.181103,8.53018368711472,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"33","D10P112103","R0","D10P112103R0",13,10,112103,0.236220609386563,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"34","D10P112103","R0","D10P112103R0",12,10,112103,0.354330890613437,5.57742815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"35","D10P112103","R0","D10P112103R0",70,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"36","D10P112103","R0","D10P112103R0",75,10,112103,0.708661781226873,6.23359592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"37","D10P112103","R0","D10P112103R0",82,10,112103,0.157480402346641,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"38","D10P112103","R0","D10P112103R0",40,10,112103,0.787402,7.54593184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"39","D10P112103","R0","D10P112103R0",52,10,112103,0.551181390613437,5.57742815644264,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"40","D10P112103","R0","D10P112103R0",23,10,112103,0.748031890613437,6.23359592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"41","D10P112103","R0","D10P112103R0",6,10,112103,0.314960804693282,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"42","D10P112103","R0","D10P112103R0",31,10,112103,0.314960804693282,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"43","D10P112103","R0","D10P112103R0",45,10,112103,0.393701,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"44","D10P112103","R0","D10P112103R0",35,10,112103,0.354330890613437,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"45","D10P112103","R0","D10P112103R0",38,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"46","D10P112103","R0","D10P112103R0",80,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"47","D10P112103","R0","D10P112103R0",5,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"48","D10P112103","R0","D10P112103R0",60,10,112103,0.472441218773127,5.57742815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"49","D10P112103","R0","D10P112103R0",19,10,112103,0.748031890613437,6.88976368711472,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"50","D10P112103","R0","D10P112103R0",22,10,112103,0.866142218773127,7.87401631288528,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"51","D10P112103","R0","D10P112103R0",61,10,112103,0.354330890613437,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"52","D10P112103","R0","D10P112103R0",68,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"53","D10P112103","R0","D10P112103R0",33,10,112103,0.236220609386563,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"54","D10P112103","R0","D10P112103R0",76,10,112103,0.551181390613437,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"55","D10P112103","R0","D10P112103R0",3,10,112103,0.9842525,7.54593184355736,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"56","D10P112103","R0","D10P112103R0",51,10,112103,0.157480402346641,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"57","D10P112103","R0","D10P112103R0",27,10,112103,0.393701,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"58","D10P112103","R0","D10P112103R0",48,10,112103,0.511811281226873,6.23359592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"59","D10P112103","R0","D10P112103R0",18,10,112103,0.275590695306718,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"60","D10P112103","R0","D10P112103R0",65,10,112103,0.905512281226873,7.21784815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"61","D10P112103","R0","D10P112103R0",14,10,112103,0.1968505,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"62","D10P112103","R0","D10P112103R0",10,10,112103,0.669291718773127,7.21784815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,10,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"63","D10P112103","R0","D10P112103R0",25,10,112103,0.118110304693282,4.26509184355736,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"64","D10P112103","R0","D10P112103R0",24,10,112103,0.393701,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"65","D10P112103","R0","D10P112103R0",74,10,112103,0.629921609386563,6.88976368711472,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"66","D10P112103","R0","D10P112103R0",42,10,112103,0.314960804693282,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"67","D10P112103","R0","D10P112103R0",1,10,112103,2.755907,10.4986881564426,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"68","D10P112103","R0","D10P112103R0",39,10,112103,0.511811281226873,6.56168,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"69","D10P112103","R0","D10P112103R0",26,10,112103,0.433071109386563,5.57742815644264,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"70","D10P112103","R0","D10P112103R0",83,10,112103,0.314960804693282,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"71","D10P112103","R0","D10P112103R0",56,10,112103,0.275590695306718,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"72","D10P112103","R0","D10P112103R0",54,10,112103,0.157480402346641,4.59317592177868,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"73","D10P112103","R0","D10P112103R0",71,10,112103,0.314960804693282,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"74","D10P112103","R0","D10P112103R0",9,10,112103,0.433071109386563,5.57742815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"75","D10P112103","R0","D10P112103R0",84,10,112103,0.669291718773127,5.90551184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"76","D10P112103","R0","D10P112103R0",8,10,112103,0.275590695306718,4.92126,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"77","D10P112103","R0","D10P112103R0",11,10,112103,0.433071109386563,59.05512,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"78","D10P112103","R0","D10P112103R0",69,10,112103,0.157480402346641,4.26509184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"79","D10P112103","R0","D10P112103R0",50,10,112103,0.1968505,4.59317592177868,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"80","D10P112103","R0","D10P112103R0",44,10,112103,0.393701,5.24934407822132,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"81","D10P112103","R0","D10P112103R0",2,10,112103,0.354330890613437,4.92126,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"82","D10P112103","R0","D10P112103R0",78,10,112103,0.157480402346641,4.26509184355736,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"83","D10P112103","R0","D10P112103R0",29,10,112103,0.0787402011733204,4.26509184355736,0,0,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"84","D10P112103","R0","D10P112103R0",37,10,112103,0.393701,5.57742815644264,0,0,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2012,NA,NA
"85","D10P112103","R1","D10P112103R1",33,10,112103,0.708661781226873,6.56168,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"86","D10P112103","R1","D10P112103R1",48,10,112103,1.02362256245375,8.2021,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"87","D10P112103","R1","D10P112103R1",70,10,112103,0.748031890613437,6.56168,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"88","D10P112103","R1","D10P112103R1",76,10,112103,1.06299271877313,7.87401631288528,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"89","D10P112103","R1","D10P112103R1",71,10,112103,0.629921609386563,6.56168,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"90","D10P112103","R1","D10P112103R1",72,10,112103,0.826772062453747,7.87401631288528,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"91","D10P112103","R1","D10P112103R1",7,10,112103,1.61417406245375,11.48294,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"92","D10P112103","R1","D10P112103R1",111,10,112103,0.551181390613437,6.23359592177868,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"93","D10P112103","R1","D10P112103R1",114,10,112103,0.236220609386563,4.59317592177868,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"94","D10P112103","R1","D10P112103R1",34,10,112103,0.629921609386563,6.23359592177868,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"95","D10P112103","R1","D10P112103R1",74,10,112103,1.25984321877313,9.18635184355736,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"96","D10P112103","R1","D10P112103R1",42,10,112103,0.511811281226873,5.57742815644264,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"97","D10P112103","R1","D10P112103R1",102,10,112103,0.393701,5.57742815644264,0,1,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"98","D10P112103","R1","D10P112103R1",110,10,112103,0.472441218773127,5.57742815644264,0,1,NA,"ABBA","bF",0.4358,1.065,-0.0179,-0.7497,0.0251,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"99","D10P112103","R1","D10P112103R1",5,10,112103,0.629921609386563,8.2021,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,NA,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
"100","D10P112103","R1","D10P112103R1",10,10,112103,1.49606378122687,10.8267718435574,0,1,NA,"PIMA","bS",0.1324,1.1955,-0.0061,-1.2545,-0.0943,14,246,5,49.0973055553436,55.6901944446564,10,"bSbF",3,"M",10,"bS",2016,NA,NA
This worked like a charm (thanks #DennyChen):
setDT(TreeData)[is.na(Age), Age:= ActualAge]
setDT(TreeData)[is.na(Age), Age:= InterpAge]
According to the answer post by #UnsoughtNine :
After setDT(), the table TreeData had been changed to a data.table object.
There is no need to setDT() again in the secong line of code.
It can also work with combining %>% pipe operator in magrittr package :
setDT(TreeData)[is.na(Age), Age:= ActualAge] %>%
.[is.na(Age), Age:= InterpAge]
Related
How to correct the output generated through str_detect/str_contains in R
I just have a column "methods_discussed" in CSV (link is https://github.com/pandas-dev/pandas/files/3496001/multiple_responses.zip) multi<- read.csv("multiple_responses.csv", header = T) This file having values name of family planning methods in the column name like: methods_discussed emergency female_sterilization male_sterilization iud NaN injectables male_condoms -77 male_condoms female_sterilization male_sterilization injectables iud male_condoms I have created a vector of all but not -77 and NAN of 8 family planning methods as: method_names = c('female_condoms', 'emergency', 'male_condoms', 'pill', 'injectables', 'iud', 'male_sterilization', 'female_sterilization') I want to create new indicator variable based on the names of vector (method_names) in the existing data frame multi2, for this I used (I) for (abc in method_names) { multi2[abc]<- as.integer(str_detect(multi2$methods_discussed, fixed(abc))) } (II) for (abc in method_names) { multi2[abc]<- as.integer(str_contains(abc,multi2$methods_discussed)) } (III) I also tried for (abc in method_names) { multi2[abc]<- as.integer(stri_detect_fixed(multi2$methods_discussed, abc)) } but the output is not matching as expected. Probably male_sterilization is a substring of female_sterilization and it shows 1(TRUE) for male_sterilization for female_sterlization also. It is shown below in the Actual output at row 2. It must show 0 (FALSE) as female_sterilization is in the method_discussed column at row 2. I also don't want to generate any thing like 0/1 (False/True) (should be blank) corresponding to -77 and blank in method_discussed (All are highlighted in Expected output. Actual Output Expected Output No error in code but only in the output.
You can add word boundaries to fix that issue. multi<- read.csv("multiple_responses.csv", header = T) method_names = c('female_condoms', 'emergency', 'male_condoms', 'pill', 'injectables', 'iud', 'male_sterilization', 'female_sterilization') for (abc in method_names) { multi[abc]<- as.integer(grepl(paste0('\\b', abc, '\\b'), multi$methods_discussed)) } multi[multi$methods_discussed %in% c('', -77), method_names] <- ''
Too many values in one argument case_when?
I am not sure why this code doesnt run. But if it breaks it into 2 smaller chunks then it works. Is there anyway i can run this whole chunk at once? When I run this code it appears the plus sign in the console and I couldnt click run in R markdown dataT4<- dataT4 %>% mutate (coupleID=case_when(id==10011~1, id==10021~2, id==10032~3, id==10041~4,id==10062~5, id==10071~6,id==10082~7, id==10092~8, id==10112~9, id==10121~10,id== 10131~11, id==10142~12, id==10151~13, id==10162~14,id==10171~15, id==10181~16, id==10202~17, id==10212~18, id==10221~19, id==10232~20, id==10242~21, id==10251~22, id==10262~23, id==10271~24, id==10292~25, id==10311~26, id==10332~27, id==10342~28, id==10351~29, id==10361~30, id==10372~31, id==10382~32, id==10391~33, id==10401~34, id==10412~35, id==10421~36, id==10432~37, id==10442~38, id==10452~39, id==10461~40, id==10471~41, id==10481~42, id==10492~43, id==10501~44, id==10511~45, id==10521~46, id==10532~47, id==10542~48, id==10562~49, id==10581~50, id==10592~51, id==10602~52, id==10611~53, id==10642~54, id==10651~55, id==10662~56, id==10672~57, id==10681~58, id==10702~59, id==10761~60, id==10782~61, id==10791~62, id==10802~63, id==10812~64, id==10822~65, id==10831~66, id==10852~67, id==10862~68, id==10881~69, id==10912~70, id==10942~71, id==10951~72, id==10962~73, id==10972~74, id==10982~75, id==10992~76, id==11001~77, id==11031~78, id==11052~79, id==11061~80, id==11072~81, id==11092~82, id==11101~83, id==11112~84, id==11171~85, id==11192~86, id==11202~87, id==11221~88, id==11231~89, id==11252~90, id==11261~91, id==11281~92, id==11292~93, id==11322~94, id==11332~95, id==11372~96, id==11382~97, id==11391~98, id==11411~99, id==11422~100, id==11441~101, id==11461~102, id==11471~103, id==11492~104, id==11501~105, id==11512~106, id==11521~107,id==11562~108,id==11591~109, id==11601~110, id==11611~111, id==11621~112, id==11632~113, id==11641~114, id==11651~115, id==11662~116, id==11682~117,id==11691~118,id==11712~119, id==11771~120, id==11782~121, id==11811~122, id==11821~123, id==11831~124, id==11841~125, id==11852~126, id==11861~127,id==11872~128,id==11882~129, id==11892~130, id==11902~131, id==11911~132, id==11922~133, id==11961~134, id==11972~135, id==11992~136,id==12011~137, id==12041~138, id==12052~139, id==12061~140, id==12081~141, id==12101~142, id==12111~143, id==12122~144, id==12131~145, id==12142~146, id==12151~147, id==12161~148, id==12182~149, id==12191~150, id==12201~151, id==12232~152, id==12261~153, id==12272~154, id==12322~155, id==12332~156, id==12342~157, id==12352~158, id==12382~159, id==12392~160, id==12401~161, id==12411~162, id==12421~163, id==12432~164, id==12441~165, id==12451~166, id==12461~167, id==12471~168, id==12492~169, id==12501~170, id==12512~171, id==12521~172, id==12542~173, id==12552~174, id==12562~175, id==12572~176, id==12581~177, id==12612~178, id==12622~179, id==12652~180, id==12662~181, id==12682~182, id==12701~183, id==12712~184, id==12731~185, id==12741~186, id==12762~187, id==12792~188, id==12802~189, id==12811~190, id==12822~191, id==12832~192, id==12841~193, id==12862~194, id==12882~195, id==12891~196, id==12911~197, id==12931~198, id==12942~199, id==12952~200, id==12961~201, id==12972~202, id==13011~203, id==13021~204, id==13032~205, id==13042~206, id==13061~207, id==13082~208, id==13102~209, id==13111~210, id==13132~211, id==13142~212, id==13151~213, id==13162~214, id==13191~215, id==13202~216, id==13212~217, id==13262~218, id==13271~219, id==13281~220, id==13311~221, id==13322~222, id==13331~223, id==13351~224, id==13361~225, id==13372~226, id==13422~227, id==13432~228, id==13452~229, id==13462~230, id==13472~231, id==13481~232, id==13501~233, id==13511~234, id==13521~235, id==13561~236, id==13571~237, id==13601~238, id==13612~239, id==13632~240, id==13642~241, id==13652~242, id==13662~243, id==13671~244, id==13681~245, id==13691~246, id==13701~247, id==13711~248, id==13732~249, id==13742~250, id==13752~251, id==13782~252, id==13842~253, id==13802~254, id==13822~255, id==13851~256, id==13872~257, id==13882~258, id==13892~259, id==13912~260, id==13921~261, id==13932~262, id==13941~263, id==13952~264, id==13971~265, id==13981~266, id==13992~267, id==14011~268, id==14021~269, id==14031~270, id==14041~271, id==14052~272, id==14072~273, id==14111~274, id==14131~275, id==14162~276, id==14172~277, id==14182~278, id==14191~279, id==14212~280, id==14222~281, id==14241~282, id==14261~283, id==14291~284, id==14302~285, id==14312~286, id==14321~287, id==14342~288, id==14352~289, id==14362~290, id==14371~291, id==14392~292, id==14402~293, id==14432~294, id==14451~295, id==14472~296, id==14482~297, id==14491~298, id==14511~299, id==14521~300, id==14531~301, id==14541~302, id==14552~303, id==14562~304, id==14572~305, id==14581~306, id==14592~307, id==14602~308, id==14621~309, id==14632~310, id==14641~311, id==14651~312, id==14671~313, id==14681~314, id==14692~315, id==14712~316, id==14722~317, id==14732~318, id==14741~319, id==14751~320, id==14781~321, id==14792~322, id==14812~323, id==14842~324, id==14852~325, id==14862~326, id==14882~327, id==14892~328, id==14901~329, id==11012~330))
As a single line it is just too long to be parsed. You may be better served putting all of these values into a separate data.frame and merging it into your data instead of using a giant case_when. Usually when I want to do something like this I'll open Excel or something similar, put column names in the first row (here that would be id and couple_id) and enter all of the values, save it as a CSV, then read the CSV into R as a data.frame, and then merge it.
You can use rank: dataT4 <- data.frame(id=c(10011, 10021, 10382, 11012)) dataT4 <- dataT4 %>% mutate (coupleID=rank(id)) dataT4 id coupleID 1 10011 1 2 10021 2 3 10382 3 4 11012 4 Data: dataT4 <- data.frame(id=c(10011, 10021, 10382, 11012))
Interpolating using approxm function goes wrong for one column
I have a data frame which contains three columns. A|B|c 10|0|0 10|5|0 10|10|0 15|0|0 15|5|0 15|10|0 When I interpolate the above data frame: df<-approxm(df,206,method="linear") Here is the output: A|B|c 10|0|0 10|1|0 10|2|0 10|3|0 10|4|0 10|5|0 10|6|0 10|7|0 10|8|0 10|9|0 10|10|0 11|8|0 12|6|0 13|4|0 14|2|0 15|0|0 15|1|0 15|2|0 15|3|0 15|4|0 15|5|0 15|6|0 15|7|0 15|8|0 15|9|0 15|10|0 Here in this output Column A with values 11,12,13 and 14 are not interpolated properly. My Expected output is: A|B|c 10|0|0 10|1|0 10|2|0 10|3|0 10|4|0 10|5|0 10|6|0 10|7|0 10|8|0 10|9|0 10|10|0 11|0|0 11|1|0 11|2|0 11|3|0 11|4|0 11|5|0 11|6|0 11|7|0 11|8|0 11|9|0 11|10|0 12|0|0 12|1|0 12|2|0 12|3|0 12|4|0 12|5|0 12|6|0 12|7|0 12|8|0 12|9|0 12|10|0 13|0|0 13|1|0 13|2|0 13|3|0 13|4|0 13|5|0 13|6|0 13|7|0 13|8|0 13|9|0 13|10|0 14|0|0 14|1|0 14|2|0 14|3|0 14|4|0 14|5|0 14|6|0 14|7|0 14|8|0 14|9|0 14|10|0 15|0|0 15|1|0 15|2|0 15|3|0 15|4|0 15|5|0 15|6|0 15|7|0 15|8|0 15|9|0 15|10|0 This is my expected output. But I'm not getting this expected output. I don't know where my code gets wrong. Can someone help me out?
Complete function worked out. tidyr::complete(df,A=full_seq(A,1),nesting(B=full_seq(B,1)),fill=list(c=0))
How to access a particular sub-set of data in R Table
I have tabular (long format) data with a number of variables. I want to load the csv once and then access a particular sub-set later on from it. For example: Blog,Region,Dim1 Individual,PK,-4.75 Individual,PK,-5.69 Individual,PK,-0.27 Individual,PK,-2.76 Individual,PK,-8.24 Individual,PK,-12.51 Individual,PK,-1.28 Individual,PK,0.95 Individual,PK,-5.96 Individual,PK,-8.81 Individual,PK,-8.46 Individual,PK,-6.15 Individual,PK,-13.98 Individual,PK,-16.43 Individual,PK,-4.09 Individual,PK,-11.06 Individual,PK,-9.04 Individual,PK,-8.56 Individual,PK,-8.13 Individual,PK,-14.46 Individual,PK,-4.21 Individual,PK,-4.96 Individual,PK,-5.48 Multiwriter,PK,-3.31 Multiwriter,PK,-5.62 Multiwriter,PK,-4.48 Multiwriter,PK,-6.08 Multiwriter,PK,-4.68 Multiwriter,PK,-6.92 Multiwriter,PK,-11.29 Multiwriter,PK,6.66 Multiwriter,PK,1.66 Multiwriter,PK,3.39 Multiwriter,PK,0.06 Multiwriter,PK,4.11 Multiwriter,PK,-1.57 Multiwriter,PK,1.33 Multiwriter,PK,-6.91 Multiwriter,PK,4.87 Multiwriter,PK,-10.87 Multiwriter,PK,6.25 Multiwriter,PK,-0.68 Multiwriter,PK,0.11 Multiwriter,PK,0.71 Multiwriter,PK,-3.8 Multiwriter,PK,-1.75 Multiwriter,PK,-5.38 Multiwriter,PK,1.24 Multiwriter,PK,-5.59 Multiwriter,PK,4.98 Multiwriter,PK,0.98 Multiwriter,PK,7.47 Multiwriter,PK,-5.25 Multiwriter,PK,-14.24 Multiwriter,PK,-1.55 Multiwriter,PK,-8.44 Multiwriter,PK,-7.67 Multiwriter,PK,5.85 Multiwriter,PK,6 Multiwriter,PK,-7.53 Multiwriter,PK,1.59 Multiwriter,PK,-9.48 Multiwriter,PK,-3.99 Multiwriter,PK,-5.82 Multiwriter,PK,1.62 Multiwriter,PK,-4.14 Multiwriter,PK,1.06 Multiwriter,PK,4.52 Multiwriter,PK,-5.6 Multiwriter,PK,-3.38 Multiwriter,PK,4.82 Multiwriter,PK,0.76 Multiwriter,PK,-4.95 Multiwriter,PK,-2.05 Column,PK,1.64 Column,PK,5.2 Column,PK,2.8 Column,PK,1.93 Column,PK,2.36 Column,PK,4.77 Column,PK,-1.92 Column,PK,-2.94 Column,PK,4.58 Column,PK,2.98 Column,PK,9.07 Column,PK,8.5 Column,PK,1.23 Column,PK,8.97 Column,PK,4.1 Column,PK,7.25 Column,PK,0.02 Column,PK,-3.48 Column,PK,1.01 Column,PK,2.7 Column,PK,-2.32 Column,PK,3.22 Column,PK,-2.37 Column,PK,-13.28 Column,PK,-4.36 Column,PK,2.91 Column,PK,4.4 Column,PK,-5.07 Column,PK,-10.24 Column,PK,12.8 Column,PK,1.92 Column,PK,13.24 Column,PK,12.32 Column,PK,12.7 Column,PK,9.95 Column,PK,12.11 Column,PK,7.63 Column,PK,11.09 Column,PK,13.04 Column,PK,12.06 Column,PK,9.49 Column,PK,8.64 Column,PK,10.05 Column,PK,6.4 Column,PK,9.64 Column,PK,3.53 Column,PK,4.78 Column,PK,9.54 Column,PK,8.49 Column,PK,2.56 Column,PK,8.82 Column,PK,-3.59 Column,PK,-3.31 Column,PK,10.05 Column,PK,-0.28 Column,PK,-0.5 Column,PK,-6.37 Column,PK,2.97 Column,PK,4.49 Column,PK,9.14 Column,PK,4.5 Column,PK,8.6 Column,PK,6.76 Column,PK,3.67 Column,PK,6.79 Column,PK,5.77 Column,PK,10.5 Column,PK,1.57 Column,PK,9.47 Individual,US,-9.85 Individual,US,-2.73 Individual,US,-0.32 Individual,US,-0.94 Individual,US,-7.51 Individual,US,-8.21 Individual,US,-7.33 Individual,US,-5.1 Individual,US,-1.58 Individual,US,-2.49 Individual,US,-1.36 Individual,US,-5.76 Individual,US,-0.48 Individual,US,-3.38 Individual,US,2.42 Individual,US,-1.71 Individual,US,-2.17 Individual,US,-2.81 Individual,US,-0.64 Individual,US,-8.88 Individual,US,-1.53 Individual,US,-1.42 Individual,US,-17.89 Individual,US,7.1 Individual,US,-4.12 Individual,US,-0.83 Individual,US,2.05 Individual,US,-5.87 Individual,US,-0.15 Individual,US,5.78 Individual,US,-1.96 Individual,US,1.77 Individual,US,-0.67 Individual,US,-10.23 Individual,US,3.37 Individual,US,-1.18 Individual,US,6.94 Individual,US,-3.86 Individual,US,2.21 Individual,US,-11.64 Individual,US,-14.71 Individual,US,-12.74 Individual,US,-6.24 Individual,US,-13.64 Individual,US,-8.53 Individual,US,-10.4 Individual,US,-6.24 Individual,US,-12.15 Individual,US,-15.96 Multiwriter,US,11.27 Multiwriter,US,3.51 Multiwriter,US,4.05 Multiwriter,US,3.81 Multiwriter,US,8.56 Multiwriter,US,6.36 Multiwriter,US,-8.99 Multiwriter,US,3.36 Multiwriter,US,3.18 Multiwriter,US,-5.22 Multiwriter,US,-8.61 Multiwriter,US,-9.02 Multiwriter,US,-6.32 Multiwriter,US,0.53 Multiwriter,US,11.03 Multiwriter,US,-5.7 Multiwriter,US,4 Multiwriter,US,-3.55 Multiwriter,US,2.79 Multiwriter,US,4.61 Multiwriter,US,-3.8 Multiwriter,US,-9.62 Multiwriter,US,-8.37 Multiwriter,US,-2.18 Multiwriter,US,-1.64 Multiwriter,US,-9.99 Multiwriter,US,-1.44 Multiwriter,US,-4.45 Multiwriter,US,-7.84 Multiwriter,US,-11.6 Multiwriter,US,-2.71 Multiwriter,US,1.2 Multiwriter,US,-6.44 Multiwriter,US,-2.64 Multiwriter,US,-11.59 Multiwriter,US,-5.9 Multiwriter,US,-3.78 Multiwriter,US,-14.99 Multiwriter,US,1.32 Multiwriter,US,-6.55 Multiwriter,US,0.92 Multiwriter,US,-5.61 Multiwriter,US,-14.16 Multiwriter,US,-10.03 Multiwriter,US,-7.08 Multiwriter,US,0.62 Multiwriter,US,-5.43 Multiwriter,US,-1.11 Multiwriter,US,-11.37 Multiwriter,US,-13.37 Multiwriter,US,-12.71 Multiwriter,US,1.86 Multiwriter,US,14.11 Multiwriter,US,-5.24 Multiwriter,US,-6.77 Multiwriter,US,-4.79 Multiwriter,US,-6.22 Multiwriter,US,3.66 Multiwriter,US,-2.65 Multiwriter,US,-2.87 Multiwriter,US,-12.32 Multiwriter,US,-7.48 Multiwriter,US,-4.84 Multiwriter,US,0.44 Column,US,8.93 Column,US,10.29 Column,US,8.31 Column,US,5.88 Column,US,8.87 Column,US,-2.9 Column,US,3.71 Column,US,8.43 Column,US,1.47 Column,US,3.05 Column,US,-1.78 Column,US,1.14 Column,US,7.2 Column,US,5.22 Column,US,5.53 Column,US,8.14 Column,US,-2.22 Column,US,0.89 Column,US,2.5 Column,US,6.77 Column,US,3.63 Column,US,2.86 Column,US,3.7 Column,US,7.52 Column,US,3.12 Column,US,0 Column,US,0.28 Column,US,6.86 Column,US,-0.32 Column,US,2.92 Column,US,-1.14 Column,US,-1.11 Column,US,4.42 Column,US,4.37 Column,US,1.09 Column,US,-3.66 Column,US,7.09 Column,US,-11.02 Column,US,-0.78 Column,US,8.44 Column,US,4.88 Column,US,-3.9 Column,US,-0.21 Column,US,6.48 Column,US,4.49 Column,US,-8.89 Column,US,-0.73 Column,US,1.76 Column,US,-4.31 Column,US,4.63 Column,US,8.91 Column,US,3.55 Column,US,6.69 Column,US,-4.45 Column,US,9.82 Column,US,6.79 Column,US,1.84 Column,US,8.97 Column,US,2.38 Column,US,4.68 Column,US,9.23 Column,US,2.85 Column,US,4.19 Column,US,2.43 Column,US,5.48 Column,US,-1.08 Column,US,7.47 Column,US,3.13 Column,US,-0.42 Column,US,-0.71 Column,US,6.51 Column,US,6.34 Column,US,3.94 Column,US,5.46 Column,US,0.39 Column,US,8.15 Column,US,7.99 Column,US,6.26 Column,US,7.91 Column,US,14.18 Column,US,7.41 Column,US,7.16 Column,US,5.6 Column,US,7.51 Column,US,6.24 Column,US,3.67 Column,US,3.84 Column,US,2.37 Column,US,-3.5 Column,US,5.02 Column,US,-6.04 Column,US,5.36 Column,US,1.98 Column,US,7.79 Column,US,0.02 Column,US,-1.9 Column,US,-2.81 Column,US,10.69 Column,US,1.65 Column,US,8.19 Column,US,1.92 How can I access values related to 'Column' with 'US' subset from 'Dim1'? I have tried to read about 'data frame, table, factor' and 'matrix' data types in R, but I could not find help how to access a subset of a complex table like this. (My real data includes additional vectors of numerical values like Dim1... i.e. Dim2, Dim3, Dim4, Dim5). But that should be the same in principle so I have not included that in this example.
I assume you want to select only the rows which have 'Column' and 'US'. If so you can select the subset using: data[data[,1]=='Column' & data[,2]=='US',]
Import data into R - argument is empty
I am trying to use a R package called GOSemSim, it requires to import a lot of data into variables with a specific format like this: data1 = c("one", "two", "three") data2 = c("A", "B", "C") When the list of data that I try to import into a variable is longer than 293 then I get the following error message: argument 293 is empty THere are no error with the "" or comma, I computed it with linux, it does not matter what data it is. This is really weird basically, I tried on two computers with no luck. I tried to import it as a CSV file but the R package won't allow it. Anyone knows why you cannot import more than 293 data? Update: Here is the code and my data at the same time, it is a one liner in R which has never been a problem for me! OQ = c("GO:0000003", "GO:0000070", "GO:0000077", "GO:0000079", "GO:0000082", "GO:0000086", "GO:0000122", "GO:0000212", "GO:0000226", "GO:0000278", "GO:0000279", "GO:0000280", "GO:0000724", "GO:0000725", "GO:0000819", "GO:0000910", "GO:0001932", "GO:0002118", "GO:0002121", "GO:0002165", "GO:0003002", "GO:0003006", "GO:0006022", "GO:0006030", "GO:0006040", "GO:0006139", "GO:0006259", "GO:0006260", "GO:0006261", "GO:0006267", "GO:0006270", "GO:0006275", "GO:0006277", "GO:0006281", "GO:0006302", "GO:0006304", "GO:0006305", "GO:0006306", "GO:0006310", "GO:0006323", "GO:0006325", "GO:0006342", "GO:0006351", "GO:0006355", "GO:0006357", "GO:0006366", "GO:0006464", "GO:0006468", "GO:0006479", "GO:0006725", "GO:0006807", "GO:0006928", "GO:0006950", "GO:0006974", "GO:0006996", "GO:0007010", "GO:0007017", "GO:0007018", "GO:0007049", "GO:0007051", "GO:0007059", "GO:0007062", "GO:0007067", "GO:0007076", "GO:0007088", "GO:0007093", "GO:0007095", "GO:0007098", "GO:0007126", "GO:0007127", "GO:0007131", "GO:0007140", "GO:0007141", "GO:0007143", "GO:0007154", "GO:0007155", "GO:0007156", "GO:0007259", "GO:0007266", "GO:0007275", "GO:0007276", "GO:0007281", "GO:0007282", "GO:0007292", "GO:0007304", "GO:0007307", "GO:0007346", "GO:0007350", "GO:0007365", "GO:0007367", "GO:0007379", "GO:0007389", "GO:0007399", "GO:0007400", "GO:0007417", "GO:0007420", "GO:0007423", "GO:0007444", "GO:0007472", "GO:0007476", "GO:0007552", "GO:0007560", "GO:0008104", "GO:0008213", "GO:0008283", "GO:0008284", "GO:0008315", "GO:0008356", "GO:0009059", "GO:0009611", "GO:0009653", "GO:0009790", "GO:0009791", "GO:0009880", "GO:0009886", "GO:0009887", "GO:0009888", "GO:0009889", "GO:0009890", "GO:0009892", "GO:0009893", "GO:0009896", "GO:0009968", "GO:0009987", "GO:0010032", "GO:0010033", "GO:0010092", "GO:0010389", "GO:0010468", "GO:0010498", "GO:0010556", "GO:0010558", "GO:0010564", "GO:0010604", "GO:0010605", "GO:0010608", "GO:0010629", "GO:0010648", "GO:0010948", "GO:0014016", "GO:0014017", "GO:0014070", "GO:0016043", "GO:0016055", "GO:0016070", "GO:0016310", "GO:0016319", "GO:0016321", "GO:0016441", "GO:0016458", "GO:0016568", "GO:0016569", "GO:0016570", "GO:0016571", "GO:0016572", "GO:0017145", "GO:0018130", "GO:0019219", "GO:0019222", "GO:0019438", "GO:0019827", "GO:0019953", "GO:0022402", "GO:0022403", "GO:0022404", "GO:0022412", "GO:0022414", "GO:0022610", "GO:0023052", "GO:0023057", "GO:0030111", "GO:0030154", "GO:0030178", "GO:0030182", "GO:0030261", "GO:0030422", "GO:0030703", "GO:0030727", "GO:0031023", "GO:0031047", "GO:0031050", "GO:0031056", "GO:0031060", "GO:0031123", "GO:0031145", "GO:0031175", "GO:0031323", "GO:0031324", "GO:0031325", "GO:0031326", "GO:0031327", "GO:0031331", "GO:0031398", "GO:0031399", "GO:0031401", "GO:0031570", "GO:0031572", "GO:0031935", "GO:0032268", "GO:0032270", "GO:0032501", "GO:0032502", "GO:0032504", "GO:0032507", "GO:0032774", "GO:0032776", "GO:0032886", "GO:0033043", "GO:0033044", "GO:0033260", "GO:0033301", "GO:0033554", "GO:0034622", "GO:0034641", "GO:0034645", "GO:0034654", "GO:0034754", "GO:0034968", "GO:0035023", "GO:0035107", "GO:0035114", "GO:0035120", "GO:0035186", "GO:0035194", "GO:0035195", "GO:0035220", "GO:0035282", "GO:0035295", "GO:0035825", "GO:0036211", "GO:0036388", "GO:0040029", "GO:0042060", "GO:0042221", "GO:0042445", "GO:0043009", "GO:0043066", "GO:0043069", "GO:0043161", "GO:0043170", "GO:0043331", "GO:0043412", "GO:0043414", "GO:0043549", "GO:0043631", "GO:0043933", "GO:0044237", "GO:0044249", "GO:0044260", "GO:0044271", "GO:0044419", "GO:0044700", "GO:0044702", "GO:0044703", "GO:0044707", "GO:0044728", "GO:0044763", "GO:0044767", "GO:0044770", "GO:0044771", "GO:0044772", "GO:0044773", "GO:0044774", "GO:0044786", "GO:0044818", "GO:0044839", "GO:0044843", "GO:0044848", "GO:0045132", "GO:0045165", "GO:0045168", "GO:0045185", "GO:0045448", "GO:0045455", "GO:0045787", "GO:0045814", "GO:0045859", "GO:0045892", "GO:0045931", "GO:0045934", "GO:0046331", "GO:0046425", "GO:0046483", "GO:0046580", "GO:0046605", "GO:0046777", "GO:0048070", "GO:0048134", "GO:0048135", "GO:0048285", "GO:0048311", "GO:0048468", "GO:0048477", "GO:0048513", "GO:0048518", "GO:0048519", "GO:0048522", "GO:0048523", "GO:0048563", "GO:0048569", "GO:0048583", "GO:0048585", "GO:0048609", "GO:0048646", "GO:0048666", "GO:0048699", "GO:0048704", "GO:0048705", "GO:0048706", "GO:0048707", "GO:0048731", "GO:0048736", "GO:0048737", "GO:0048754", "GO:0048856", "GO:0048863", "GO:0048865", "GO:0048867", "GO:0048869", "GO:0050789", "GO:0050793", "GO:0050794", "GO:0050896", "GO:0051052", "GO:0051058", "GO:0051128", "GO:0051171", "GO:0051172", "GO:0051225", "GO:0051235", "GO:0051246", "GO:0051247", "GO:0051252", "GO:0051253", "GO:0051276", "GO:0051297", "GO:0051299", "GO:0051301", "GO:0051302", "GO:0051321", "GO:0051325", "GO:0051329", "GO:0051338", "GO:0051351", "GO:0051443", "GO:0051445", "GO:0051641", "GO:0051646", "GO:0051651", "GO:0051704", "GO:0051716", "GO:0051726", "GO:0051783", "GO:0051785", "GO:0060255", "GO:0060429", "GO:0060548", "GO:0060688", "GO:0060966", "GO:0060968", "GO:0060993", "GO:0061138", "GO:0065003", "GO:0065004", "GO:0065007", "GO:0070192", "GO:0070507", "GO:0070887", "GO:0070918", "GO:0071103", "GO:0071359", "GO:0071822", "GO:0071824", "GO:0071840", "GO:0071897", "GO:0071900", "GO:0072028", "GO:0072078", "GO:0072079", "GO:0072088", "GO:0080090", "GO:0090068", "GO:0090304", "GO:0090306", "GO:0098609", "GO:1901071", "GO:1901360", "GO:1901362", "GO:1901576", "GO:1901987", "GO:1901988", "GO:1901990", "GO:1901991", "GO:1902275", "GO:1902299", "GO:1902589", "GO:1902679", "GO:1902749", "GO:1903046", "GO:1903047", "GO:1903308", "GO:1903322", "GO:2000026", "GO:2000112", "GO:2000113", "GO:2001141")
The error message in itself is informative. If one tries to make it reproducible, it's best to work with small subsets. It usually helps to have a dead stare at your data before trying to reproduce the behavior. For example, OQ = c("GO:0000003", "GO:2001141", ) Notice that there are two elements of this character vector. Or are they? Error in c("GO:0000003", "GO:2001141", ) : argument 3 is empty Number 3 is the key. R is expecting three elements. Notice the comma after the second element. Once you remove it, you'll be able to create the QQ variable. Scan your real example. I'm sure there's a , , somewhere. EDIT I tried copy/pasting your code into a script in Rstudio and it produced the error you describe. If you scroll right, you'll notice that syntax coloring is not working at around position 5000. I have folded the code so that it fits on screen and it runs fine. This is how I folded the vector and it worked. OQ = c("GO:0000003", "GO:0000070", "GO:0000077", "GO:0000079", "GO:0000082", "GO:0000086", "GO:0000122", "GO:0000212", "GO:0000226", "GO:0000278", "GO:0000279", "GO:0000280", "GO:0000724", "GO:0000725", "GO:0000819", "GO:0000910", "GO:0001932", "GO:0002118", "GO:0002121", "GO:0002165", "GO:0003002", "GO:0003006", "GO:0006022", "GO:0006030", "GO:0006040", "GO:0006139", "GO:0006259", "GO:0006260", "GO:0006261", "GO:0006267", "GO:0006270", "GO:0006275", "GO:0006277", "GO:0006281", "GO:0006302", "GO:0006304", "GO:0006305", "GO:0006306", "GO:0006310", "GO:0006323", "GO:0006325", "GO:0006342", "GO:0006351", "GO:0006355", "GO:0006357", "GO:0006366", "GO:0006464", "GO:0006468", "GO:0006479", "GO:0006725", "GO:0006807", "GO:0006928", "GO:0006950", "GO:0006974", "GO:0006996", "GO:0007010", "GO:0007017", "GO:0007018", "GO:0007049", "GO:0007051", "GO:0007059", "GO:0007062", "GO:0007067", "GO:0007076", "GO:0007088", "GO:0007093", "GO:0007095", "GO:0007098", "GO:0007126", "GO:0007127", "GO:0007131", "GO:0007140", "GO:0007141", "GO:0007143", "GO:0007154", "GO:0007155", "GO:0007156", "GO:0007259", "GO:0007266", "GO:0007275", "GO:0007276", "GO:0007281", "GO:0007282", "GO:0007292", "GO:0007304", "GO:0007307", "GO:0007346", "GO:0007350", "GO:0007365", "GO:0007367", "GO:0007379", "GO:0007389", "GO:0007399", "GO:0007400", "GO:0007417", "GO:0007420", "GO:0007423", "GO:0007444", "GO:0007472", "GO:0007476", "GO:0007552", "GO:0007560", "GO:0008104", "GO:0008213", "GO:0008283", "GO:0008284", "GO:0008315", "GO:0008356", "GO:0009059", "GO:0009611", "GO:0009653", "GO:0009790", "GO:0009791", "GO:0009880", "GO:0009886", "GO:0009887", "GO:0009888", "GO:0009889", "GO:0009890", "GO:0009892", "GO:0009893", "GO:0009896", "GO:0009968", "GO:0009987", "GO:0010032", "GO:0010033", "GO:0010092", "GO:0010389", "GO:0010468", "GO:0010498", "GO:0010556", "GO:0010558", "GO:0010564", "GO:0010604", "GO:0010605", "GO:0010608", "GO:0010629", "GO:0010648", "GO:0010948", "GO:0014016", "GO:0014017", "GO:0014070", "GO:0016043", "GO:0016055", "GO:0016070", "GO:0016310", "GO:0016319", "GO:0016321", "GO:0016441", "GO:0016458", "GO:0016568", "GO:0016569", "GO:0016570", "GO:0016571", "GO:0016572", "GO:0017145", "GO:0018130", "GO:0019219", "GO:0019222", "GO:0019438", "GO:0019827", "GO:0019953", "GO:0022402", "GO:0022403", "GO:0022404", "GO:0022412", "GO:0022414", "GO:0022610", "GO:0023052", "GO:0023057", "GO:0030111", "GO:0030154", "GO:0030178", "GO:0030182", "GO:0030261", "GO:0030422", "GO:0030703", "GO:0030727", "GO:0031023", "GO:0031047", "GO:0031050", "GO:0031056", "GO:0031060", "GO:0031123", "GO:0031145", "GO:0031175", "GO:0031323", "GO:0031324", "GO:0031325", "GO:0031326", "GO:0031327", "GO:0031331", "GO:0031398", "GO:0031399", "GO:0031401", "GO:0031570", "GO:0031572", "GO:0031935", "GO:0032268", "GO:0032270", "GO:0032501", "GO:0032502", "GO:0032504", "GO:0032507", "GO:0032774", "GO:0032776", "GO:0032886", "GO:0033043", "GO:0033044", "GO:0033260", "GO:0033301", "GO:0033554", "GO:0034622", "GO:0034641", "GO:0034645", "GO:0034654", "GO:0034754", "GO:0034968", "GO:0035023", "GO:0035107", "GO:0035114", "GO:0035120", "GO:0035186", "GO:0035194", "GO:0035195", "GO:0035220", "GO:0035282", "GO:0035295", "GO:0035825", "GO:0036211", "GO:0036388", "GO:0040029", "GO:0042060", "GO:0042221", "GO:0042445", "GO:0043009", "GO:0043066", "GO:0043069", "GO:0043161", "GO:0043170", "GO:0043331", "GO:0043412", "GO:0043414", "GO:0043549", "GO:0043631", "GO:0043933", "GO:0044237", "GO:0044249", "GO:0044260", "GO:0044271", "GO:0044419", "GO:0044700", "GO:0044702", "GO:0044703", "GO:0044707", "GO:0044728", "GO:0044763", "GO:0044767", "GO:0044770", "GO:0044771", "GO:0044772", "GO:0044773", "GO:0044774", "GO:0044786", "GO:0044818", "GO:0044839", "GO:0044843", "GO:0044848", "GO:0045132", "GO:0045165", "GO:0045168", "GO:0045185", "GO:0045448", "GO:0045455", "GO:0045787", "GO:0045814", "GO:0045859", "GO:0045892", "GO:0045931", "GO:0045934", "GO:0046331", "GO:0046425", "GO:0046483", "GO:0046580", "GO:0046605", "GO:0046777", "GO:0048070", "GO:0048134", "GO:0048135", "GO:0048285", "GO:0048311", "GO:0048468", "GO:0048477", "GO:0048513", "GO:0048518", "GO:0048519", "GO:0048522", "GO:0048523", "GO:0048563", "GO:0048569", "GO:0048583", "GO:0048585", "GO:0048609", "GO:0048646", "GO:0048666", "GO:0048699", "GO:0048704", "GO:0048705", "GO:0048706", "GO:0048707", "GO:0048731", "GO:0048736", "GO:0048737", "GO:0048754", "GO:0048856", "GO:0048863", "GO:0048865", "GO:0048867", "GO:0048869", "GO:0050789", "GO:0050793", "GO:0050794", "GO:0050896", "GO:0051052", "GO:0051058", "GO:0051128", "GO:0051171", "GO:0051172", "GO:0051225", "GO:0051235", "GO:0051246", "GO:0051247", "GO:0051252", "GO:0051253", "GO:0051276", "GO:0051297", "GO:0051299", "GO:0051301", "GO:0051302", "GO:0051321", "GO:0051325", "GO:0051329", "GO:0051338", "GO:0051351", "GO:0051443", "GO:0051445", "GO:0051641", "GO:0051646", "GO:0051651", "GO:0051704", "GO:0051716", "GO:0051726", "GO:0051783", "GO:0051785", "GO:0060255", "GO:0060429", "GO:0060548", "GO:0060688", "GO:0060966", "GO:0060968", "GO:0060993", "GO:0061138", "GO:0065003", "GO:0065004", "GO:0065007", "GO:0070192", "GO:0070507", "GO:0070887", "GO:0070918", "GO:0071103", "GO:0071359", "GO:0071822", "GO:0071824", "GO:0071840", "GO:0071897", "GO:0071900", "GO:0072028", "GO:0072078", "GO:0072079", "GO:0072088", "GO:0080090", "GO:0090068", "GO:0090304", "GO:0090306", "GO:0098609", "GO:1901071", "GO:1901360", "GO:1901362", "GO:1901576", "GO:1901987", "GO:1901988", "GO:1901990", "GO:1901991", "GO:1902275", "GO:1902299", "GO:1902589", "GO:1902679", "GO:1902749", "GO:1903046", "GO:1903047", "GO:1903308", "GO:1903322", "GO:2000026", "GO:2000112", "GO:2000113", "GO:2001141")