Currently, I am trying to go through a select few columns of a database. The columns contain part numbers and some part names need to be removed before put into a vector. I am able to do this for one column using the following loop. However, I want to be able to go through all the columns I want without having to copy the loop for each column.
Ordered = NULL
for (i in x1$V4) {
if (i != as.character("PartX")) #if statement of i is not equal to PartX
Ordered[i] <- i #puts i in new vector
}
z=data.frame(table(Ordered))
I want to be able to create a table for all of the part numbers using table
. I tried to do this through apply
but didn't work well. I know this code works I just need to expand it over multiple columns.
This is what my dataset currently looks like.
# V4 V5 V6 V7 V8
# PartA PartE PartC PartX PartX
# PartC PartX PartX PartX PartX
# PartF PartB PartE PartD PartA
# PartE PartA PartC PartX PartX
# PartA PartE PartD PartX PartX
# PartB PartA PartC PartF PartX
This is what I want my newest vector/dataset to end up like.
# V1
# PartA
# PartC
# PartF
# PartE
# PartA
# PartB
# PartE
# PartB
# PartA
# PartE
# PartA
# PartC
# PartE
# PartC
# PartD
# PartC
# PartD
# PartF
# PartA