data.table - How can I specify columns in R to be used in matches (without listing each individually)? -


Assume that there are three columns of data to me ( Sample 1 , Sample 2 ,

and Sample 3 ). I want all the rows in which the letter appears in any of the b or h columns. It works fine:
  data & lt; - Sample 1 = Representative ("A", 5), Sample 2 = C (Rep. ("S1_100", "s1_200", "s2_300", "s1_400", "s1_500"), B ", 2), representative (" A ", 3)), sample 3 = C (representative (" A ", 4)," H ")) data # Pankti_nam sample 1 sample 2 sample 3 # Sl_l00 Aba # Sl_200 Aba # S1_300 aaa # s1_400 aaa # s1_500 aah bh & lt; - c ('b', 'h') bh_data & lt; - subsets (data, (sample1% in% bh | sample2% Bh | in sample3 %% bh)) bh_data # row_name sample1 sample2 sample3 # s1_100 aba # s1_200 aba # s1_500 aah   

However, since I am asking the same question about each column, there is no less redundant way to do this?

But in reality, we have more than 800 columns and more than 70,000 rows, and we want to be able to choose many or some specific columns to search. For example, using hundreds of column names, unless I try to make the script R script.

Try

  indx & lt; - Reduce (`` lapply (df [, - 1], `% in%`, bh) df [indx,] # row_name sample1 sample2 sample3 # 1 s1_100 aba # 2 s1_200 aba # 5 s1_500 aah   

or data.table

  is using the library (data.table) nm1 and lieutenant; - Paste 0 ( "sample", 1: 3) Set DT (DF) [DF [Down ( `` `Lapply (SD,% 'in`% BH)), Sdicol = 1 nm]] # Pankti_nam sample 1 sample 2 sample 3 # 1: s1_100 Aba # 2: s1_200 Aba # 3: s1_500 ah   

data
  df & lt; - Structure (list Row_name = c ("s1_200", "s1_200", "s1_300", "s1_400", "s1_500"), sample 1 = c ("a", "a", "a", "a" "a"), Sample2 = c ( "b", "b", "a", "a", "a"), sample 3 = c ( "a", "a", "a", "a" , "H"),) Name = C ( "Pankti_nam", "Sample 1", "Sample 2", "Sample 3"), class = "Detakfrem" Panktiknam = C (NA, 5L))  < / Pre>  

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -