How to create a single data set that contains two data frames using an excel file

51 Views Asked by At

I need to create a single data set from an excel file that looks likes the following picture 1. When I export the file to mimic it in excel, the format does not work correctly. This is what the file looks like when it is exported as an excel 2. However, when I mimic the exported file with my own data and upload it to r, it doesn't import correct and mirror that of image 1 as it should. This is what it looks like when I mirror the format and import my data and import it to r (it should look like image 1)3.

> puechdesIII
$available
         <180 180-250 >250
Calou    103      60   50
Celi      68      23   46
Kinou    114      52   94
Lucette   65      45  269
Schnock   75      35    8
Suzanne  115      76   72

$used
        <180 180-250 >250
Calou     40       8    5
Celi      13       2    8
Kinou     21       4    8
Lucette   15       3   33
Schnock   42       5    0
Suzanne   34      12    5

Code used with the given dataset:

puechdesIII
data(puechdesIII)
used <- puechdesIII$used
available <- puechdesIII$available
1

There are 1 best solutions below

1
On

I'm assuming puechdessIII is a dataframe class object but it doesn't look like it. If it is try this:

available<-puechdesIII$available
used<-puechdesIII$used
names(available) <- c("x", "y", "z")
names(used) <- c("x", "y", "z")
combined.df<-rbind(available, used)

next time please provide a usable sample of your data to help us better understand and help.

After your comment, try this:

data<-data("puechdesIII")
x<-as.data.frame(puechdesIII)
x1<-x[,4:6]
x2<-x[,1:3]
names(x1) <- c("180", "180.250", "250")
names(x2) <- c("180", "180.250", "250")
df<-rbind(x1,x2)
type<-c(rep("Available",6), rep("Used",6))
frame<-cbind(df,type)