R: automatically copy large amounts of data

Jeffery Chen

I'm new in R, I have some data like this:

Yes No age    color  place
12  5  12-18  red    right
2   33 19-30  yellow left
...

I need to create new database,

answer   age    color  place
Yes      12-18  red    right 
Yes      12-18  red    right
...                          (12 times)

No       12-18  red    right
No       12-18  red    right
...                          (5 times)

How could I do?

A5C1D2H2I1M1N2O1R2T1

I would use a combination of expandRows from my "splitstackshape" package and melt from "reshape2".

Assuming your data are called "mydf", try:

library(splitstackshape)
library(reshape2)
dfLong <- expandRows(
  melt(mydf, measure.vars = c("Yes", "No"), 
       variable.name = "answer"), "value")

Here are the first 20 rows:

head(dfLong, 20)
#        age  color place answer
# 1    12-18    red right    Yes
# 1.1  12-18    red right    Yes
# 1.2  12-18    red right    Yes
# 1.3  12-18    red right    Yes
# 1.4  12-18    red right    Yes
# 1.5  12-18    red right    Yes
# 1.6  12-18    red right    Yes
# 1.7  12-18    red right    Yes
# 1.8  12-18    red right    Yes
# 1.9  12-18    red right    Yes
# 1.10 12-18    red right    Yes
# 1.11 12-18    red right    Yes
# 2    19-30 yellow  left    Yes
# 2.1  19-30 yellow  left    Yes
# 3    12-18    red right     No
# 3.1  12-18    red right     No
# 3.2  12-18    red right     No
# 3.3  12-18    red right     No
# 3.4  12-18    red right     No
# 4    19-30 yellow  left     No

## Confirm that there are the correct number of combinations
table(dfLong$age, dfLong$answer)
#        
#         Yes No
#   12-18  12  5
#   19-30   2 33

The order is a little bit different from what you've posted--doing all "Yes" answers first and then the "No" answers instead of alternating between them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

STL containers and large amounts of data

From Dev

Is there an alternative to AtomicReferenceArray for large amounts of data?

From Dev

Export of large amounts of data with JMSSerializerBundle

From Dev

Form not submitting with large amounts of data

From Dev

counting and subtotaling large amounts of data

From Dev

Mule Aggregate large amounts of data

From Dev

STL containers and large amounts of data

From Dev

Managing Large amounts of Data in Javascript

From Dev

Is there an alternative to AtomicReferenceArray for large amounts of data?

From Dev

Form not submitting with large amounts of data

From Dev

Locally store large amounts of data

From Dev

Collection View automatically handles large amounts of records?

From Dev

Can file transfer speed be increased with an application when copy-pasting large amounts of data?

From Dev

Large file copy with GCD - Dispatch IO consumes large amounts of memory

From Dev

Large file copy with GCD - Dispatch IO consumes large amounts of memory

From Dev

How to delete large amounts of data from Foxpro

From Dev

Faster calculation for large amounts of data / inner loop

From Dev

Chrome extension store large amounts of data

From Dev

Method for copying large amounts of data in C#

From Dev

WPF controls performance issues with large amounts of data

From Dev

How to Stream Through Large Amounts of Twitter Data?

From Dev

BigCommerce PHP API - Pulling large amounts of data

From Dev

Set up a database to import large amounts of data

From Dev

Improving performance of dictionary lookup for large amounts of data

From Dev

UI for displaying large amounts of hierachical data

From Dev

Deleting large amounts of data from MongoDB

From Dev

Spring Batch - Processing Large Amounts of Data

From Dev

SQLite vs Core Data: saving large amounts of data

From Dev

SQLite vs Core Data: saving large amounts of data

Related Related

  1. 1

    STL containers and large amounts of data

  2. 2

    Is there an alternative to AtomicReferenceArray for large amounts of data?

  3. 3

    Export of large amounts of data with JMSSerializerBundle

  4. 4

    Form not submitting with large amounts of data

  5. 5

    counting and subtotaling large amounts of data

  6. 6

    Mule Aggregate large amounts of data

  7. 7

    STL containers and large amounts of data

  8. 8

    Managing Large amounts of Data in Javascript

  9. 9

    Is there an alternative to AtomicReferenceArray for large amounts of data?

  10. 10

    Form not submitting with large amounts of data

  11. 11

    Locally store large amounts of data

  12. 12

    Collection View automatically handles large amounts of records?

  13. 13

    Can file transfer speed be increased with an application when copy-pasting large amounts of data?

  14. 14

    Large file copy with GCD - Dispatch IO consumes large amounts of memory

  15. 15

    Large file copy with GCD - Dispatch IO consumes large amounts of memory

  16. 16

    How to delete large amounts of data from Foxpro

  17. 17

    Faster calculation for large amounts of data / inner loop

  18. 18

    Chrome extension store large amounts of data

  19. 19

    Method for copying large amounts of data in C#

  20. 20

    WPF controls performance issues with large amounts of data

  21. 21

    How to Stream Through Large Amounts of Twitter Data?

  22. 22

    BigCommerce PHP API - Pulling large amounts of data

  23. 23

    Set up a database to import large amounts of data

  24. 24

    Improving performance of dictionary lookup for large amounts of data

  25. 25

    UI for displaying large amounts of hierachical data

  26. 26

    Deleting large amounts of data from MongoDB

  27. 27

    Spring Batch - Processing Large Amounts of Data

  28. 28

    SQLite vs Core Data: saving large amounts of data

  29. 29

    SQLite vs Core Data: saving large amounts of data

HotTag

Archive