Hello all,
I have the code below:
vectorstates <- unique(vectorstates)
for (x in vectorstates){
filtered <- filter(removal, removal$State %in% x)
datafiltered <- filtered[order(filtered[,'Pneumonia],filtered[,’Hospital.Name’]),]
hospital <- filter(datafiltered, datafiltered[,'Pneumonia] %in% datafiltered[3,'Pneumonia'])
hospital <- data.frame(hospital$Hospital.Name)
ID <- data.frame(x)
Collected <- cbind(hospital,ID)
Emptydataframe <- rbind(Emptydataframe,Collected)
}
print(Emptydataframe)
I am trying to create a dataframe that goes through each character (State in the USA) of the vector, vectorstates, and then finds the name of the hospital (Hospital.Name), that corresponds to the lowest value of the column "Pneumonia" for that particular state.
My object vectorstates, looks like this:
vectorstates <- [1] "AL" "AK" "AZ" "AR" "CA" "CO" "CT" "DE" "DC" "FL" "GA" "HI" "ID" "IL"
[15] "IN" "IA" "KS" "KY" "LA" "ME" "MD" "MA" "MI" "MN" "MS" "MO" "MT" "NE"
[29] "NV" "NH" "NJ" "NM" "NY" "NC" "ND" "OH" "OK" "OR" "PA" "PR" "RI" "SC"
[43] "SD" "TN" "TX" "UT" "VT" "VI" "VA" "WA" "WV" "WI" "WY" "GU"
Everytime I run this code, I get the error:
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 0, 1
Would anybody be able to give me a helping hand as to why I am getting this error?
structure(list(Target = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("70.1075",
"101.71", "149.1155", "220.2225", "326.8835"), class = "factor"),
Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("Beaconed-0",
"Beaconed-0.5", "Beaconed-2", "Probe-0", "Probe-0.5", "Probe-2"
), class = "factor"), ID = c("P_200214103155", "P_200214123342",
"P_200217101213", "P_200219091823", "P_200219102411", "P_200219111605",
"P_200219123120", "P_200219163622", "P_200219175102", "P_200220130332",
"P_200220145557", "P_200221101028", "P_200224092247", "P_200225171612",
"P_200225184226", "P_200214103155", "P_200214123342", "P_200217101213",
"P_200219091823", "P_200219102411", "P_200219111605", "P_200219123120",
"P_200219163622", "P_200219175102", "P_200220130332", "P_200220145557",
"P_200221101028", "P_200224092247", "P_200225171612", "P_200225184226",
"P_200214103155", "P_200214123342", "P_200217101213", "P_200219091823",
"P_200219102411", "P_200219111605", "P_200219123120", "P_200219163622",
"P_200219175102", "P_200220130332", "P_200220145557", "P_200221101028",
"P_200224092247", "P_200225171612", "P_200225184226", "P_200214103155",
"P_200214123342", "P_200217101213", "P_200219091823", "P_200219102411"
), Absolutefirststoperror = c(5.8022, 8.6136, 7.7334, 3.3824,
4.1562, 8.3978, 6.7964, 5.8266, 5.0725, 4.153, 5.977, 4.5832,
7.57525, 4.66425, 7.55, 6.7488, 7.8048, 7.5708, 7.2012, 4.3314,
8.2928, 5.1, 3.0236, 4.7482, 5.1454, 3.8708, 5.6708, 6.7938,
4.4986, 6.9404, 5.7226, 6.5688, 6.9756, 4.3906, 13.908, 13.6114,
4.8192, 4.7482, 3.2736, 2.5638, 6.602, 3.7658, 9.3858, 8.9644,
8.5324, 14.7138, 10.7642, 9.6718, 16.383, 5.9138), transform = c(1.75823715597722,
2.15334234951937, 2.04554861065665, 1.21858551669378, 1.42460119527448,
2.12796976678432, 1.91639306022947, 1.76243363984623, 1.62383379271783,
1.42383096464862, 1.78791876984212, 1.52239744411223, 2.02488635415117,
1.53992704966997, 2.02154756326093, 1.90936471130232, 2.05473892903946,
2.02429874218263, 1.97424767880133, 1.46589081539103, 2.1153876684533,
1.62924053973028, 1.10644817443588, 1.55776559885943, 1.63810311164787,
1.35346120402465, 1.73533020126134, 1.91601043156591, 1.50376623726006,
1.93735940974538, 1.74442324757176, 1.88233116741244, 1.94241834551317,
1.47946589200769, 2.63246421414561, 2.61090767691312, 1.57260793918338,
1.55776559885943, 1.18589029677517, 0.941490532895897, 1.887372633431,
1.32596032208019, 2.23919790881364, 2.1932611778793, 2.14387068183553,
2.68878582892075, 2.37622581314541, 2.26921443485221, 2.79624421183813,
1.7772886027996), transform2 = c(2.40877562259335, 2.9348935244741,
2.78089913517193, 1.83913022921162, 2.03867604096384, 2.89789578832642,
2.60699060220784, 2.41383512278697, 2.25222112591104, 2.03789106676486,
2.44479037956222, 2.14084095625995, 2.75231720555607, 2.15968747739112,
2.74772633280682, 2.59784526098072, 2.79370721443748, 2.75150867707154,
2.68350517048132, 2.08120157601324, 2.87972220882501, 2.25831795812724,
1.73885019481265, 2.17903648432054, 2.26834741607189, 1.96743487821071,
2.38134415824341, 2.60649189524924, 2.12099033472574, 2.6344638923318,
2.39219564417294, 2.5629670306112, 2.64113611917296, 2.09537586127167,
3.72934310569569, 3.68936308866449, 2.19526763744196, 2.17903648432054,
1.80930926046378, 1.60118705965293, 2.56943573572098, 1.94056692747248,
3.06362530345994, 2.99406078762606, 2.92102721657981, 3.83585714019696,
3.28088402720974, 3.10995176811474, 4.0475918766595, 2.43183058620456
)), row.names = c(NA, -50L), class = "data.frame")