[R] Breaking down a list into a table
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Nov 30 17:18:25 CET 2016
The tidyr::separate function modifies data frames. You did not give it a data frame. Re-read your preferred R introductory material on what a data frame is (R comes with "Introduction to R").
You also did not give a reproducible example... e.g. does not execute as-is in a clean R work space.
library(tidyr)
input <- data.frame( kop=rep( "w;d;e;f", 5 ) )
output <- separate( input, kop, into=c( "C1", "C2", "C3", "C4" ), sep=";" )
You really should read the documentation for any contributed package you use. (This presumes that you keep track of the fact that you are using them... which is a good idea as there are thousands of them). I recommend
vignette("tidy-data")
and
?separate
in this case.
--
Sent from my phone. Please excuse my brevity.
On November 30, 2016 7:18:19 AM PST, Ferri Leberl <ferri.leberl at gmx.at> wrote:
>
>Thank to Ulrik for the hint.
>However, I don't comprehend the function until now:
>
>For example I made up an array "input":
>
>input
> kop
>[1,] "w;d;e;f"
>[2,] "w;d;e;f"
>[3,] "w;d;e;f"
>[4,] "w;d;e;f"
>[5,] "w;d;e;f"
>
>and tried to break it into four cols with commmand:
>
>output<-separate(into,kop,into=c("a","b","c","d"),sep=";")
>
>R returned:
>
>Fehler in UseMethod("separate_") :
>nicht anwendbare Methode für 'separate_' auf Objekt der Klasse
>"c('matrix', 'character')" angewendet
>
>Could you please explain me my mistake?
>
>Thank you in advance!
>
>Yours, Ferri
>
>
>
>
>
>
>
>Gesendet: Dienstag, 22. November 2016 um 14:57 Uhr
>Von: "Ulrik Stervbo" <ulrik.stervbo at gmail.com>
>An: "Ferri Leberl" <ferri.leberl at gmx.at>, "r-helpr-project.org"
><r-help at r-project.org>
>Betreff: Re: [R] Breaking down a list into a table
>
>Hi Ferri,
> It sounds like the function 'separate' from the tidyr package is what
>you look for,
>
>HTH
>Ulrik
>
>On Tue, 22 Nov 2016 at 14:49 Ferri Leberl
><ferri.leberl at gmx.at[mailto:ferri.leberl at gmx.at]> wrote:
>
>Dear All,
>I asked for support to deal with a hirarchy within a character
>separated list.
>I solved the problem crudely but effectively by
>
>- Choosing for a TSV as input, where in columns that may contain
>several (or as well no) items the items are separated via semicolon
>- adding semicolons to the first row to grant that the first row has
>the maximum number of semicolons of this column
>- grasping the column(x<-myarray[,y], where y is some integer value)
>and saving it as a TSV (with only one column)
>- importing it again, defining it semicolumn-separated, with fill
>option
>
>To all those who feel pain reading this: Is there a shortcut?
>Thank you in advance.
>Yours, Ferri
>
>______________________________________________
>R-help at r-project.org[mailto:R-help at r-project.org] mailing list -- To
>UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help[https://stat.ethz.ch/mailman/listinfo/r-help]
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html[http://www.R-project.org/posting-guide.html]
>and provide commented, minimal, self-contained, reproducible code.
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list