How to separate a dataframe based on specific string in column name [duplicate]Split string by last two characters in R? (/negative string indices)How to sort a dataframe by multiple column(s)Drop data frame columns by nameSplit column at delimiter in data frameSplit comma-separated strings in a column into separate rowsDynamically select data frame columns using $ and a vector of column nameshow to make a bar plot for a list of dataframes?Divide multiple columns of one data frame by row names value of another dataframe RR dataframe combining rows based on columnsSearching for a list of string in a dataframe in Rconvert 2 columns dataframe to matrix by slicing rownames - R

How can I support myself financially as a 17 year old with a loan?

Independent, post-Brexit Scotland - would there be a hard border with England?

How to model the curly cable part of the phone

I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?

Have I damaged my car by attempting to reverse with hand/park brake up?

Out of scope work duties and resignation

Lie super algebra presentation of the Kähler identities

Does a card have a keyword if it has the same effect as said keyword?

How to apply differences on part of a list and keep the rest

Why does this rising edge detector using a capacitor and a resistor work?

Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?

Understanding trademark infringements in a world where many dictionary words are trademarks?

Is latino sine flexione dead?

Why do only some White Walkers shatter into ice chips?

How might a mountain bowl form?

Manager is threatening to grade me poorly if I don't complete the project

Are there any Final Fantasy Spirits in Super Smash Bros Ultimate?

What is the most remote airport from the center of the city it supposedly serves?

Using field size much larger than necessary

Upside-Down Pyramid Addition...REVERSED!

BOOM! Perfect Clear for Mr. T

Make some Prime Squares!

Why was the battle set up *outside* Winterfell?

What to use instead of cling film to wrap pastry



How to separate a dataframe based on specific string in column name [duplicate]


Split string by last two characters in R? (/negative string indices)How to sort a dataframe by multiple column(s)Drop data frame columns by nameSplit column at delimiter in data frameSplit comma-separated strings in a column into separate rowsDynamically select data frame columns using $ and a vector of column nameshow to make a bar plot for a list of dataframes?Divide multiple columns of one data frame by row names value of another dataframe RR dataframe combining rows based on columnsSearching for a list of string in a dataframe in Rconvert 2 columns dataframe to matrix by slicing rownames - R






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1
















This question already has an answer here:



  • Split string by last two characters in R? (/negative string indices)

    5 answers



I have a huge data that I cannot split into two sets



 df<- structure(list(name = structure(1:3, .Label = c("a", "b", "c"
), class = "factor"), X3C_AALI_01A = c(651L, 2L, 1877L), X3C_AALJ_01B = c(419L,
2L, 1825L), X3C_AALK_01A = c(1310L, 52L, 1286L), X4H_AAAK_11B = c(2978L,
4L, 1389L), X5L_AAT0_01B = c(2576L, 15L, 1441L), X5L_AAT1_01A = c(2886L,
5L, 921L), X5T_A9QA_03A = c(929L, 3L, 935L), A1_A0SI_10A = c(1578L,
1L, 2217L), A1_A0SK_07C = c(3003L, 6L, 2984L), A1_A0SO_01A = c(6413L,
0L, 3577L), A1_A0SP_05B = c(5157L, 5L, 4596L), A2_A04P_01A = c(4283L,
6L, 2508L), X5L_AAh1_10A = c(2886L, 5L, 921L), X5T_A0QA_03A = c(929L,
3L, 935L), A1_A0Sm_10A = c(1578L, 1L, 2217L), A1_ArSK_01A = c(3003L,
6L, 2984L), A1_AfSO_01A = c(6413L, 0L, 3577L), A1_AuSP_05A = c(5157L,
5L, 4596L), A2_Ap4P_11A = c(4283L, 6L, 2508L)), class = "data.frame", row.names = c(NA,
-3L))


basically , I want to split the data based on the last character of the column name. for example if you look at the above data, the second column is like this 3C_AALI_01A which I want to generate two data sets based on the _01A



So those columns that have 01 to 09 values I want them to be in one data frame and those ones that have 10 to whatever number want them to be in the second data frame. For example in the above example data.



the columns with the following names should be in one data frame



3C_AALI_01A
3C_AALJ_01B
3C_AALK_01A
5L_AAT0_01B
5L_AAT1_01A
5T_A9QA_03A
A1_A0SK_07C
A1_A0SO_01A
A1_A0SP_05B
A2_A04P_01A
5T_A0QA_03A
A1_ArSK_01A
A1_AfSO_01A
A1_AuSP_05A


and the columns with the following names should be in another data frame



4H_AAAK_11B
A1_A0SI_10A
5L_AAh1_10A
A1_A0Sm_10A
A2_Ap4P_11A









share|improve this question















marked as duplicate by smci, Maurits Evers r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Apr 12 at 5:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

    – smci
    Apr 10 at 10:47

















1
















This question already has an answer here:



  • Split string by last two characters in R? (/negative string indices)

    5 answers



I have a huge data that I cannot split into two sets



 df<- structure(list(name = structure(1:3, .Label = c("a", "b", "c"
), class = "factor"), X3C_AALI_01A = c(651L, 2L, 1877L), X3C_AALJ_01B = c(419L,
2L, 1825L), X3C_AALK_01A = c(1310L, 52L, 1286L), X4H_AAAK_11B = c(2978L,
4L, 1389L), X5L_AAT0_01B = c(2576L, 15L, 1441L), X5L_AAT1_01A = c(2886L,
5L, 921L), X5T_A9QA_03A = c(929L, 3L, 935L), A1_A0SI_10A = c(1578L,
1L, 2217L), A1_A0SK_07C = c(3003L, 6L, 2984L), A1_A0SO_01A = c(6413L,
0L, 3577L), A1_A0SP_05B = c(5157L, 5L, 4596L), A2_A04P_01A = c(4283L,
6L, 2508L), X5L_AAh1_10A = c(2886L, 5L, 921L), X5T_A0QA_03A = c(929L,
3L, 935L), A1_A0Sm_10A = c(1578L, 1L, 2217L), A1_ArSK_01A = c(3003L,
6L, 2984L), A1_AfSO_01A = c(6413L, 0L, 3577L), A1_AuSP_05A = c(5157L,
5L, 4596L), A2_Ap4P_11A = c(4283L, 6L, 2508L)), class = "data.frame", row.names = c(NA,
-3L))


basically , I want to split the data based on the last character of the column name. for example if you look at the above data, the second column is like this 3C_AALI_01A which I want to generate two data sets based on the _01A



So those columns that have 01 to 09 values I want them to be in one data frame and those ones that have 10 to whatever number want them to be in the second data frame. For example in the above example data.



the columns with the following names should be in one data frame



3C_AALI_01A
3C_AALJ_01B
3C_AALK_01A
5L_AAT0_01B
5L_AAT1_01A
5T_A9QA_03A
A1_A0SK_07C
A1_A0SO_01A
A1_A0SP_05B
A2_A04P_01A
5T_A0QA_03A
A1_ArSK_01A
A1_AfSO_01A
A1_AuSP_05A


and the columns with the following names should be in another data frame



4H_AAAK_11B
A1_A0SI_10A
5L_AAh1_10A
A1_A0Sm_10A
A2_Ap4P_11A









share|improve this question















marked as duplicate by smci, Maurits Evers r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Apr 12 at 5:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

    – smci
    Apr 10 at 10:47













1












1








1









This question already has an answer here:



  • Split string by last two characters in R? (/negative string indices)

    5 answers



I have a huge data that I cannot split into two sets



 df<- structure(list(name = structure(1:3, .Label = c("a", "b", "c"
), class = "factor"), X3C_AALI_01A = c(651L, 2L, 1877L), X3C_AALJ_01B = c(419L,
2L, 1825L), X3C_AALK_01A = c(1310L, 52L, 1286L), X4H_AAAK_11B = c(2978L,
4L, 1389L), X5L_AAT0_01B = c(2576L, 15L, 1441L), X5L_AAT1_01A = c(2886L,
5L, 921L), X5T_A9QA_03A = c(929L, 3L, 935L), A1_A0SI_10A = c(1578L,
1L, 2217L), A1_A0SK_07C = c(3003L, 6L, 2984L), A1_A0SO_01A = c(6413L,
0L, 3577L), A1_A0SP_05B = c(5157L, 5L, 4596L), A2_A04P_01A = c(4283L,
6L, 2508L), X5L_AAh1_10A = c(2886L, 5L, 921L), X5T_A0QA_03A = c(929L,
3L, 935L), A1_A0Sm_10A = c(1578L, 1L, 2217L), A1_ArSK_01A = c(3003L,
6L, 2984L), A1_AfSO_01A = c(6413L, 0L, 3577L), A1_AuSP_05A = c(5157L,
5L, 4596L), A2_Ap4P_11A = c(4283L, 6L, 2508L)), class = "data.frame", row.names = c(NA,
-3L))


basically , I want to split the data based on the last character of the column name. for example if you look at the above data, the second column is like this 3C_AALI_01A which I want to generate two data sets based on the _01A



So those columns that have 01 to 09 values I want them to be in one data frame and those ones that have 10 to whatever number want them to be in the second data frame. For example in the above example data.



the columns with the following names should be in one data frame



3C_AALI_01A
3C_AALJ_01B
3C_AALK_01A
5L_AAT0_01B
5L_AAT1_01A
5T_A9QA_03A
A1_A0SK_07C
A1_A0SO_01A
A1_A0SP_05B
A2_A04P_01A
5T_A0QA_03A
A1_ArSK_01A
A1_AfSO_01A
A1_AuSP_05A


and the columns with the following names should be in another data frame



4H_AAAK_11B
A1_A0SI_10A
5L_AAh1_10A
A1_A0Sm_10A
A2_Ap4P_11A









share|improve this question

















This question already has an answer here:



  • Split string by last two characters in R? (/negative string indices)

    5 answers



I have a huge data that I cannot split into two sets



 df<- structure(list(name = structure(1:3, .Label = c("a", "b", "c"
), class = "factor"), X3C_AALI_01A = c(651L, 2L, 1877L), X3C_AALJ_01B = c(419L,
2L, 1825L), X3C_AALK_01A = c(1310L, 52L, 1286L), X4H_AAAK_11B = c(2978L,
4L, 1389L), X5L_AAT0_01B = c(2576L, 15L, 1441L), X5L_AAT1_01A = c(2886L,
5L, 921L), X5T_A9QA_03A = c(929L, 3L, 935L), A1_A0SI_10A = c(1578L,
1L, 2217L), A1_A0SK_07C = c(3003L, 6L, 2984L), A1_A0SO_01A = c(6413L,
0L, 3577L), A1_A0SP_05B = c(5157L, 5L, 4596L), A2_A04P_01A = c(4283L,
6L, 2508L), X5L_AAh1_10A = c(2886L, 5L, 921L), X5T_A0QA_03A = c(929L,
3L, 935L), A1_A0Sm_10A = c(1578L, 1L, 2217L), A1_ArSK_01A = c(3003L,
6L, 2984L), A1_AfSO_01A = c(6413L, 0L, 3577L), A1_AuSP_05A = c(5157L,
5L, 4596L), A2_Ap4P_11A = c(4283L, 6L, 2508L)), class = "data.frame", row.names = c(NA,
-3L))


basically , I want to split the data based on the last character of the column name. for example if you look at the above data, the second column is like this 3C_AALI_01A which I want to generate two data sets based on the _01A



So those columns that have 01 to 09 values I want them to be in one data frame and those ones that have 10 to whatever number want them to be in the second data frame. For example in the above example data.



the columns with the following names should be in one data frame



3C_AALI_01A
3C_AALJ_01B
3C_AALK_01A
5L_AAT0_01B
5L_AAT1_01A
5T_A9QA_03A
A1_A0SK_07C
A1_A0SO_01A
A1_A0SP_05B
A2_A04P_01A
5T_A0QA_03A
A1_ArSK_01A
A1_AfSO_01A
A1_AuSP_05A


and the columns with the following names should be in another data frame



4H_AAAK_11B
A1_A0SI_10A
5L_AAh1_10A
A1_A0Sm_10A
A2_Ap4P_11A




This question already has an answer here:



  • Split string by last two characters in R? (/negative string indices)

    5 answers







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 at 10:45









smci

15.8k679110




15.8k679110










asked Mar 22 at 22:13









LearnerLearner

38010




38010




marked as duplicate by smci, Maurits Evers r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Apr 12 at 5:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by smci, Maurits Evers r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Apr 12 at 5:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

    – smci
    Apr 10 at 10:47

















  • Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

    – smci
    Apr 10 at 10:47
















Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

– smci
Apr 10 at 10:47





Really you want negative string indexing. Also, your dataframe is kind of transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string. If your dataframe was structured like that, you could use tidyr::separate(..., sep=-1)

– smci
Apr 10 at 10:47












2 Answers
2






active

oldest

votes


















1














df1 <- df[,grep('0[1-9].$',colnames(df))]
df2 <- df[,-grep('0[1-9].$',colnames(df))]





share|improve this answer

























  • Quotes in at least two of your answers are incorrect. Please edit.

    – Roman Luštrik
    Mar 22 at 22:30











  • Could you elaborate? Or edit and I will accept?

    – Wil
    Mar 22 at 22:38






  • 1





    It was an issue with the keyboard on this device. Do they appear correct to you now?

    – Wil
    Mar 22 at 22:49


















0














You could use tidyr::separate(..., last=-1) approach



  • which uses negative string indexing, which is what you really want here

  • also, your dataframe is transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string.





share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    df1 <- df[,grep('0[1-9].$',colnames(df))]
    df2 <- df[,-grep('0[1-9].$',colnames(df))]





    share|improve this answer

























    • Quotes in at least two of your answers are incorrect. Please edit.

      – Roman Luštrik
      Mar 22 at 22:30











    • Could you elaborate? Or edit and I will accept?

      – Wil
      Mar 22 at 22:38






    • 1





      It was an issue with the keyboard on this device. Do they appear correct to you now?

      – Wil
      Mar 22 at 22:49















    1














    df1 <- df[,grep('0[1-9].$',colnames(df))]
    df2 <- df[,-grep('0[1-9].$',colnames(df))]





    share|improve this answer

























    • Quotes in at least two of your answers are incorrect. Please edit.

      – Roman Luštrik
      Mar 22 at 22:30











    • Could you elaborate? Or edit and I will accept?

      – Wil
      Mar 22 at 22:38






    • 1





      It was an issue with the keyboard on this device. Do they appear correct to you now?

      – Wil
      Mar 22 at 22:49













    1












    1








    1







    df1 <- df[,grep('0[1-9].$',colnames(df))]
    df2 <- df[,-grep('0[1-9].$',colnames(df))]





    share|improve this answer















    df1 <- df[,grep('0[1-9].$',colnames(df))]
    df2 <- df[,-grep('0[1-9].$',colnames(df))]






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 22 at 22:48

























    answered Mar 22 at 22:17









    WilWil

    1,4371217




    1,4371217












    • Quotes in at least two of your answers are incorrect. Please edit.

      – Roman Luštrik
      Mar 22 at 22:30











    • Could you elaborate? Or edit and I will accept?

      – Wil
      Mar 22 at 22:38






    • 1





      It was an issue with the keyboard on this device. Do they appear correct to you now?

      – Wil
      Mar 22 at 22:49

















    • Quotes in at least two of your answers are incorrect. Please edit.

      – Roman Luštrik
      Mar 22 at 22:30











    • Could you elaborate? Or edit and I will accept?

      – Wil
      Mar 22 at 22:38






    • 1





      It was an issue with the keyboard on this device. Do they appear correct to you now?

      – Wil
      Mar 22 at 22:49
















    Quotes in at least two of your answers are incorrect. Please edit.

    – Roman Luštrik
    Mar 22 at 22:30





    Quotes in at least two of your answers are incorrect. Please edit.

    – Roman Luštrik
    Mar 22 at 22:30













    Could you elaborate? Or edit and I will accept?

    – Wil
    Mar 22 at 22:38





    Could you elaborate? Or edit and I will accept?

    – Wil
    Mar 22 at 22:38




    1




    1





    It was an issue with the keyboard on this device. Do they appear correct to you now?

    – Wil
    Mar 22 at 22:49





    It was an issue with the keyboard on this device. Do they appear correct to you now?

    – Wil
    Mar 22 at 22:49













    0














    You could use tidyr::separate(..., last=-1) approach



    • which uses negative string indexing, which is what you really want here

    • also, your dataframe is transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string.





    share|improve this answer



























      0














      You could use tidyr::separate(..., last=-1) approach



      • which uses negative string indexing, which is what you really want here

      • also, your dataframe is transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string.





      share|improve this answer

























        0












        0








        0







        You could use tidyr::separate(..., last=-1) approach



        • which uses negative string indexing, which is what you really want here

        • also, your dataframe is transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string.





        share|improve this answer













        You could use tidyr::separate(..., last=-1) approach



        • which uses negative string indexing, which is what you really want here

        • also, your dataframe is transposed, it would be more normal to have one single column name with the names, and numerical columns a, b, c. Like t(df) without the unwanted coercion to string.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 10 at 10:42









        smcismci

        15.8k679110




        15.8k679110













            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript