I have a csv in this format:
Col1_Status Col1_Value Col2_Status Col2_Value Col3_Status Col3__Value
LOW 5 HIGH 5 LOW 5
LOW 8 HIGH 8 LOW 8
HIGH 82 HIGH 8 LOW 7
HIGH 83 NORMAL 8 LOW 7
HIGH 82 NORMAL 8 LOW 7
I want to create a new dataframe with the high and low as columns, for example:
Col1_High Col1_Low Col2_High Col2_Low Col3_High Col3_Low
82 5 5 NA NA 5
83 8 8 NA NA 8
82 NA 8 NA NA 7
NA NA NA NA NA 7
NA NA NA NA NA 7
What is the best way to go about this?
So far I think:
#extract the Status Columns from original file into DataFrame
statusDF <- ret[grepl("Status", colnames(ret))]
#extract the Value Columns from original file into DataFrame
originalValueDF <- ret[grepl("Value", colnames(ret))]
#create new columns attribute_high and attribute_low
for(i in names(originalValueDF)){
newValueDF <- originalValueDF[[paste(i, 'High', sep = "_")]]
newValueDF <- originalValueDF[[paste(i, 'Low', sep = "_")]]
}
#populate both columns based on value in attribute status column
for(i in names(originalValueDF)){
if (originalValueDF$i == "High"){
temp <- # stuck here
}
}
Any advise is appreciated
Col3_Low = c(5, 8)... where is 7? What are your criteria?