How to turn a generic dataframe?

Lince202

I have this dataframe:

  freq      1      2        3       4
1  100     10     20       30      40
2  100   0.50   1.00      1.5       2
3  200     50     60       70      80
4  200    2.5      3      3.5       4   

I want to turn this dataframe in this way:

  freq      1      2        
1  100     10   0.50
2  100     20     1 
3  100     30   1.50
4  100     40     2
5  200     50   2.50
6  200     60     3 
7  200     70   3.50
8  200     80     4

How can i do that?

I need something that runs for a generic dataframe, not only this case.

akrun

We can try

 i1 <- c(TRUE, FALSE)
 data.frame(freq = rep(df1$freq,  each =(ncol(df1)-1)/2), 
   `1` = c(t(df1[i1,-1])), `2` = c(t(df1[!i1,-1])), check.names=FALSE)
#  freq  1   2
#1  100 10 0.5
#2  100 20 1.0
#3  100 30 1.5
#4  100 40 2.0
#5  200 50 2.5
#6  200 60 3.0
#7  200 70 3.5
#8  200 80 4.0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I turn this function to a generic type?

From Dev

How do I turn a dataframe into a series of lists?

From Dev

How to turn pandas dataframe row into ordereddict fast

From Dev

How do I turn a dataframe into a series of lists?

From Dev

How to turn pandas dataframe row into ordereddict fast

From Dev

How to turn dataframe into pair count in R?

From Dev

How can I turn picture to structured dataframe?

From Dev

R: how to turn variables to values in dataframe for ggplot

From Dev

How to turn a Ceylon Sequential or array into a generic Tuple with the appropriate type?

From Dev

How do I turn pandas DataFrame groupby results into a DataFrame?

From Dev

How how to turn arules apriori output into dataframe in R

From Dev

How how to turn arules apriori output into dataframe in R

From Dev

How to turn tuple of tuples in unicode to pandas dataframe in python

From Dev

How do I turn an array of column names into a pandas Dataframe?

From Dev

How to turn a Pandas Dataframe into a Dictionary of Dataframes by grouping columns

From Dev

How to turn tuple of tuples in unicode to pandas dataframe in python

From Dev

How to turn a DataFrame column of binary variables into multiple columns of dummy variables

From Dev

how can I turn a number into the value of a new dataframe?

From Java

Turn txt file into dataframe

From Dev

How to implement Java 8 generic method that returns zipped stream where objects from two streams appear in turn?

From Dev

How do I turn an event dataframe with "end" and "start" rows into a regrouped by event dataframe?

From Dev

Is there a way to turn regular/generic gamepad to autofire gamepad?

From Dev

R: Turn List Data into Dataframe

From Dev

Python: How to pull a 'fake' modeled date from a dataframe header string and turn it into a new column

From Dev

How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

From Dev

How to get Turn By Turn Instruction in HERE SDK

From Dev

How to turn on robolectric logging

From Dev

How to turn gpclibPermit() to TRUE

From Dev

How to turn a boolean into a message?

Related Related

  1. 1

    How do I turn this function to a generic type?

  2. 2

    How do I turn a dataframe into a series of lists?

  3. 3

    How to turn pandas dataframe row into ordereddict fast

  4. 4

    How do I turn a dataframe into a series of lists?

  5. 5

    How to turn pandas dataframe row into ordereddict fast

  6. 6

    How to turn dataframe into pair count in R?

  7. 7

    How can I turn picture to structured dataframe?

  8. 8

    R: how to turn variables to values in dataframe for ggplot

  9. 9

    How to turn a Ceylon Sequential or array into a generic Tuple with the appropriate type?

  10. 10

    How do I turn pandas DataFrame groupby results into a DataFrame?

  11. 11

    How how to turn arules apriori output into dataframe in R

  12. 12

    How how to turn arules apriori output into dataframe in R

  13. 13

    How to turn tuple of tuples in unicode to pandas dataframe in python

  14. 14

    How do I turn an array of column names into a pandas Dataframe?

  15. 15

    How to turn a Pandas Dataframe into a Dictionary of Dataframes by grouping columns

  16. 16

    How to turn tuple of tuples in unicode to pandas dataframe in python

  17. 17

    How to turn a DataFrame column of binary variables into multiple columns of dummy variables

  18. 18

    how can I turn a number into the value of a new dataframe?

  19. 19

    Turn txt file into dataframe

  20. 20

    How to implement Java 8 generic method that returns zipped stream where objects from two streams appear in turn?

  21. 21

    How do I turn an event dataframe with "end" and "start" rows into a regrouped by event dataframe?

  22. 22

    Is there a way to turn regular/generic gamepad to autofire gamepad?

  23. 23

    R: Turn List Data into Dataframe

  24. 24

    Python: How to pull a 'fake' modeled date from a dataframe header string and turn it into a new column

  25. 25

    How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

  26. 26

    How to get Turn By Turn Instruction in HERE SDK

  27. 27

    How to turn on robolectric logging

  28. 28

    How to turn gpclibPermit() to TRUE

  29. 29

    How to turn a boolean into a message?

HotTag

Archive