I'm doing some string manipulation on a vector of file names, and noticed
something curious.  When I strsplit the vector, I get a list of
character vectors.
The list is numbered, as lists are.  When I cast that list as a data
frame with 'as.data.frame()', the resulting columns have names derived
from the original filenames.

Example code is below.  My question is, where are these names stored
in the list?  Are there methods that can access this from the list?
Is there a way to preserve them verbatim?  Thanks
-Ed

> example.names
[1] "con1-1-masked-bottom-green.tsv" "con1-1-masked-bottom-red.tsv"
[3] "con1-1-masked-top-green.tsv"    "con1-1-masked-top-red.tsv"
> example.list <- strsplit(example.names, "-")
> example.list
[[1]]
[1] "con1"      "1"         "masked"    "bottom"    "green.tsv"

[[2]]
[1] "con1"    "1"       "masked"  "bottom"  "red.tsv"

[[3]]
[1] "con1"      "1"         "masked"    "top"       "green.tsv"

[[4]]
[1] "con1"    "1"       "masked"  "top"     "red.tsv"

> example.df <- as.data.frame(example.list)
> example.df
  c..con1....1....masked....bottom....green.tsv..
1                                            con1
2                                               1
3                                          masked
4                                          bottom
5                                       green.tsv
  c..con1....1....masked....bottom....red.tsv..
1                                          con1
2                                             1
3                                        masked
4                                        bottom
5                                       red.tsv
  c..con1....1....masked....top....green.tsv..
1                                         con1
2                                            1
3                                       masked
4                                          top
5                                    green.tsv
  c..con1....1....masked....top....red.tsv..
1                                       con1
2                                          1
3                                     masked
4                                        top
5                                    red.tsv

______________________________________________
R-help@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.

Reply via email to