[R] about transforming a data.frame

Bogdan Tanasa tanasa at gmail.com
Fri May 29 23:54:25 CEST 2015


Hi Jim,

yes, thank you, that is the desired output. one more question please :
after using the dataframe :

df <- data.frame (row_names = c("B4:B5:B6", "B7:B8:B9", "D4:D5:D6",
"D10:D11:D12", "D10:D11:D12", "E10:E11:E12", "A1:A2:A3", "B10:B11:B12"),
col_names = c
("B1:B2:B3","B1:B2:B3","H4:H5:H6","F10:F11:F12","H1:H2:H3","G7:G8:G9","D1:D2:D3","B1:B2:B3"),
CT = c(5,2,2,2,2,2,4,4) )

and :

table(df$row_names,df$CT)
table(df$col_names,df$CT)

how could I quickly verify that "B1:B2:B3" (for example) hits the CT values
of 2,4,5  at least one time ? an example is in

table(df$col_names,df$CT) ?

thank you very much,

-- bogdan



On Fri, May 29, 2015 at 2:40 PM, Jim Lemon <drjimlemon at gmail.com> wrote:

> Hi Bogdan,
> Sarah has already suggested this, but doesn't:
>
> table(df$row_names,df$CT)
> table(df$col_names,df$CT)
>
> give you what you want?
>
> Jim
>
>
> On Sat, May 30, 2015 at 7:11 AM, John Kane <jrkrideau at inbox.com> wrote:
> > Bogdan, the request was for data in dput() format.
> >
> > Type ?dput for more information.
> >
> > Do dput(myfile) copy the ouput and paste into the email
> >
> > You should get something like:
> > structure(list(c1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
> > 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
> > 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
> > 8L, 8L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L), .Label = c("(0.509,0.614]",
> > "(0.614,0.718]", "(0.718,0.822]", "(0.822,0.926]", "(0.926,1.03]",
> > "(1.03,1.13]", "(1.13,1.24]", "(1.24,1.34]", "(1.34,1.45]", "(1.45,1.55]"
> > ), class = "factor"), s1 = c(0.51, 0.52, 0.58, 0.58, 0.59, 0.6,
> > 0.63, 0.65, 0.68, 0.74, 0.74, 0.75, 0.77, 0.77, 0.77, 0.78, 0.79,
> > 0.84, 0.84, 0.85, 0.87, 0.93, 0.93, 0.95, 0.99, 1.04, 1.09, 1.11,
> > 1.13, 1.14, 1.14, 1.14, 1.17, 1.18, 1.19, 1.22, 1.22, 1.23, 1.28,
> > 1.29, 1.3, 1.32, 1.37, 1.38, 1.38, 1.4, 1.43, 1.47, 1.52, 1.55
> > )), .Names = c("c1", "s1"), row.names = c(NA, -50L), class =
> "data.frame")
> >
> > Data in duput() format is the preferred way to get data in R-help since
> it provides a perfect copy of what you have on your machine.  Any other way
> of providing data risks the recipients reading it into R differently than
> it is on your machine.
> >
> > John Kane
> > Kingston ON Canada
> >
> >
> >> -----Original Message-----
> >> From: tanasa at gmail.com
> >> Sent: Fri, 29 May 2015 13:58:20 -0700
> >> To: sarah.goslee at gmail.com
> >> Subject: Re: [R] about transforming a data.frame
> >>
> >> Hi Sarah,
> >>
> >> thank you for your help. I have simplified the example, by reading the
> >> elements in a data frame, eg :
> >>
> >> df <- data.frame (row_names = c("B4:B5:B6", "B7:B8:B9", "D4:D5:D6",
> >> "D10:D11:D12", "D10:D11:D12", "E10:E11:E12", "A1:A2:A3", "B10:B11:B12"),
> >> col_names = c
> >>
> ("B1:B2:B3","B1:B2:B3","H4:H5:H6","F10:F11:F12","H1:H2:H3","G7:G8:G9","D1:D2:D3","B1:B2:B3"),
> >> CT = c(5,2,2,2,2,2,4,4) )
> >>
> >> I have used the the count() in the plyr package :
> >>
> >> count_row_names <- count(df$row_names)
> >> count_col_names <- count(df$col_names)
> >>
> >> however, I would need to correlate these UNIQUE ELEMENTS in the columns
> >> "row_names" or "col_names" with the numbers they associate in the  CT
> >> columns, eg :
> >>
> >> ""B1:B2:B3" associate with "5, 2, 4" (in CT column), or "D10:D11:D12"
> >> associate with "2" (in the CT column).
> >>
> >> thank you very much,
> >>
> >> bogdan
> >>
> >>
> >>
> >>
> >> On Fri, May 29, 2015 at 1:32 PM, Sarah Goslee <sarah.goslee at gmail.com>
> >> wrote:
> >>
> >>> Hi,
> >>>
> >>> Please use dput() to provide your data, as it can get somewhat mangled
> >>> by copy and pasting, especially if you post in HTML (as you are asked
> >>> not to do in the posting guide).
> >>>
> >>> What is a unique element? is "B4:B5:B6" an element, or are "B4" and
> >>> "B5" each elements? That is, what is the result you expect to obtain
> >>> for the sample data you provided?
> >>>
> >>> What code have you tried? I would think table() might be involved, and
> >>> possibly strsplit(), but will refrain from putting more time into this
> >>> until you provide a reproducible dataset with dput() and some clearer
> >>> idea of your intent.
> >>>
> >>> Sarah
> >>>
> >>> On Fri, May 29, 2015 at 4:19 PM, Bogdan Tanasa <tanasa at gmail.com>
> wrote:
> >>>> Dear all,
> >>>>
> >>>> I would appreciate a suggestion on the following : I am working with a
> >>>> data.frame (below) :
> >>>>
> >>>>   EXP    CT   row_names   col_names
> >>>> 1   test -5    B4:B5:B6    B1:B2:B3
> >>>> 2   test -2    B7:B8:B9    B1:B2:B3
> >>>> 3   test -2    D4:D5:D6    H4:H5:H6
> >>>> 4   test -2    D10:D11:D12 F10:F11:F12
> >>>> 5   test -2    D10:D11:D12    H1:H2:H3
> >>>> 6   test -2    E10:E11:E12    G7:G8:G9
> >>>> 7   test -4     A1:A2:A3    D1:D2:D3
> >>>> 8   test -4   B10:B11:B12    B1:B2:B3
> >>>>
> >>>> what would be the easiest way to consider UNIQUE elements in the
> >>> ROW_NAMES
> >>>> or the UNIQUE elements in the COL_NAMES and :
> >>>>
> >>>> print how many times these UNIQUE ELEMENTS associate with the numbers
> >>>> -5,
> >>>> -2, or -4 (these numbers are on the column names CT) ..
> >>>>
> >>>> thanks,
> >>>>
> >>>> bogdan
> >>>>
> >>> --
> >>> Sarah Goslee
> >>> http://www.functionaldiversity.org
> >>>
> >>
> >>       [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> 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.
> >
> > ____________________________________________________________
> > FREE ONLINE PHOTOSHARING - Share your photos online with your friends
> and family!
> > Visit http://www.inbox.com/photosharing to find out more!
> >
> > ______________________________________________
> > 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list