I have a problem when dealing with the missings in R and then extract an Excel file without the missings, here are the data I want to manipulate
col1=c("Sujeto1","Sujeto2","Sujeto3","Sujeto4","Sujeto5","Sujeto6")
col2=c("A",NA,NA,"G",NA,NA)
col3=c(NA,NA,NA,"K","H","Z")
col4=c(NA,"P",NA,NA,NA,"Q")
col5=c(NA,NA,NA,NA,NA,NA)
col6=c(NA,NA,NA,"B","C",NA)
col7=c("E",NA,NA,"D",NA,"Y")
data=data.frame(col1,col2,col3,col4,col5,col6,col7)
> data
col1 col2 col3 col4 col5 col6 col7
1 Sujeto1 A <NA> <NA> NA <NA> E
2 Sujeto2 <NA> <NA> P NA <NA> <NA>
3 Sujeto3 <NA> <NA> <NA> NA <NA> <NA>
4 Sujeto4 G K <NA> NA B D
5 Sujeto5 <NA> H <NA> NA C <NA>
6 Sujeto6 <NA> Z Q NA <NA> Y
And I want the output to be an Excel that looks like this:
As you can see, the missings are not there and each individual has a different number of columns. To make the output in Excel you have to use the following command:
library(xlsx)
write.xlsx2(x=data,file="Data.xlsx",row.names = F)
It is the first time I ask around here, I have read the manual and I would say that I do not meet any requirements since in principle it does not seem that much code is needed to make the transformation that I ask and it seems to me sufficiently concrete what I ask. If not, I apologize in advance for the inconvenience caused and edit what is necessary to be in an appropriate format for this forum.
Thank you very much for the help, really.