Try this. The last function removes everything but the
last part, i.e. the part after the -. Then we order the
columns, except the first column, by their last part
and finally split the result by the last part of the ID.
This gives a list of data frames, two in this case:
> last <- function(x) s
Does this do what you want:
> x
ID S1-a S1-b S2-a S2-b
1 001-A1234
2 001-B5678
3 002-A9 10 11 12
4 002-B 13 14 15 16
> # split the column names
> t.n <- strsplit(names(x)[-1], '-')
> t.n <- sort(sapply(t.n, function(a) paste(a[2],a[1])))
> # c
You're right. Using read.csv, the first column is a factor, not string
(or should I use str?). The following is a 2x2 version of the data frame
after read.csv
IDS1-a S1-b S2-a S2-b
1 001-A1 2 3 4
2 001-B5 6 7 8
3 002-A9 101112
4
Are you using 'read.csv'? At least include an 'str' of the object you
are wanting to convert so that we know the structure of it, since we
can not guess at what it is.
On Sat, Jul 25, 2009 at 4:32 AM, Junqian Gordon Xu wrote:
> Actually when I read the spreadsheet from cvs file, "S1-[abcd]" are t
Actually when I read the spreadsheet from cvs file, "S1-[abcd]" are the
header and "T1-[abcd]" are the strings in first column of the data frame.
Gordon
On 07/25/2009 03:13 AM, jim holtman wrote:
It it not entirely clear what the format of your data is. If you have
a dataframe that you would l
It it not entirely clear what the format of your data is. If you have
a dataframe that you would like to separate into several different one
based on the value in a column, then something like this will work:
df.list <- split(yourDF, yourDF$column)
This will create a list of dataframes, split acc
I have a multidimensional data which looks like the following:
"S1-a" "S2-b" "S3-c" "S4-d" "S5-a" "S6-b" "S7-c" "S8-d"
"T1-A"
"T1-B"
"T1-C"
"T1-D"
"T2-A"
"T2-B"
"T2-C"
"T2-D"
I read it from csv file and would like to have 16 separate data frames
like this
"S1-a" "S2-a" "S1-b"
7 matches
Mail list logo