[R] about transforming a data.frame

Jim Lemon drjimlemon at gmail.com
Sat May 30 01:21:32 CEST 2015


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



More information about the R-help mailing list