I'm having a dataframe with NA values
df <- data.frame("About" = c("Ram","Std 8",NA,NA,NA,"John", "Std 9", NA, NA,NA,NA),
"Questions" = c(NA,NA,"Q1","Q2","Q3",NA,NA,"Q1","Q2","Q3","Q4"),
"Ratings" = c(NA,NA,7,7,7,NA,NA,7,7,7,7), stringsAsFactors = FALSE)
The expected output is as follows:
expectedOutput <- data.frame("About" = c("Ram","John"),
"Standard" = c("Std 8", "Std 9"),
"Q1" = c(7,7),
"Q2" = c(7,7),
"Q3" = c(7,7),
"Q4" = c(0,7))
I tried to achieve this using the reshape function
DataTransform <- reshape(df, idvar = "About", v.names = "Ratings", timevar = "Questions", direction = "wide")
Can anyone help me to achieve the expected output by reshaping the given dataframe?
Thanks in advance!!