[R] about transforming a data.frame

Bogdan Tanasa tanasa at gmail.com
Sat May 30 01:29:28 CEST 2015


Thanks a lot Jim. If I may ask one more little question please,

shall I ask the question ""How can I verify that "B1:B2:B3" is paired with
ALL of the values 2, 4 and 5 ",

regardless of the pairing value (in our case, for the code below, the
"pairing value" for "B1:B2:B3" is 1, but it can be 2,3,4, etc BUT NOT
zero),

how could I test for that ? or this is the way that "apply" works for "all"
argument ?

a good documentation for "apply" function will help too . thanks, and happy
weekend !

-- bogdan


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

> Hi Bogdan,
> If you mean "How can I verify that "B1:B2:B3" is paired with all of
> the values 2, 4 and 5"
>
> apply(table(df$col_names,df$CT),1,all)
>
> and if you mean "How can I verify that "B1:B2:B3" is paired with at
> least one of the values 2, 4 and 5"
>
> apply(table(df$col_names,df$CT),1,any)
>
> Jim
>
>
> 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
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list