8
I have a file in table form. I need to separate the contents of a specific column in other columns, the data are separated by ;
.
Well I managed to do this, but the problem is that the content will result for each row a different number of columns. And by this code it replicates up to the content until it reaches the number of columns. I wanted it to display IN.
By my code I get this:
v1 v2 v3 p/sep sep sep sep sep
dados1 dados2 dados3 a;b;c a b c a
dados1 dados2 dados3 a;c a c a c
dados1 dados2 dados3 a a a a a
dados1 dados2 dados3 a;b a b a b
dados1 dados2 dados3 a;b;c;d a b c d
dados1 dados2 dados3 a;b a b a b
But the result I hope to have is:
v1 v2 v3 separar sep sep sep sep
dados1 dados2 dados3 a;b;c a b c NA
dados1 dados2 dados3 a;c a c a c
dados1 dados2 dados3 a a NA NA NA
dados1 dados2 dados3 a;b a b NA NA
dados1 dados2 dados3 a;b;c;d a b c d
dados1 dados2 dados3 a;b a b NA NA
library(reshape)
file_split = data.frame(file,colsplit(file$separar,split=";",names="buffer",))
In the second line of the expected response is actually "a c a c" or "a c NA"
– Marcos Banik
There’s another error in the code, there’s no comma after
"buffer"
, and also this argument does not make much sense because it defines a column name, being that 4 are created. Not that it’s a big problem in this case, but the ideal is to put the exact code and the exact output generated, apparently you edited some things by hand.– Molx
'buffer" was a syntax error, I thought it would repeat the buffer name as header of all new columns @Molx
– Joyce Maia
was typo @Marcosbanik
– Joyce Maia
@Joycemaia if you want to use "buffer", you need to differentiate the columns somehow, because columns with equal names are not a good idea. One way to do this is to use
paste
as I did in my reply.– Molx