0

I was wondering how I could go about changing some data like this from a dataframe i created:

Variable Freq                           and       Variable Freq                
01       3                                        M        10
02       2                                        
03       4
04       5

to

01       3                                        
02       2                                        
03       4
04       5
M        10

The code i am using to get those 2 tables is :

y = as.data.frame(length(unique(index_visit$PatientID)))
x = as.data.frame(table(index_visit$ProcedureID))
Christopher Yee
  • 535
  • 2
  • 5
  • 14
  • 1
    Try `rbind(DF1,DF2)`. Your `x` and `y` are rather strange data.frames, by the way. For example, `y` should have only one value in it, according to your code `as.data.frame(length(...anything...))` – Frank May 12 '15 at 18:03
  • yeah sorry about that. that was just some sample output. I tried to use R bind but it gave me the error: Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match – Christopher Yee May 12 '15 at 18:10
  • Np. Check out `names(x)` and `names(y)` to see that they do not have the same number of columns, as the error says. – Frank May 12 '15 at 18:12
  • ah i see, there is only one column from the length. is there any way to make it 2 columns so like: PatientIDs, freq? – Christopher Yee May 12 '15 at 18:16
  • Not sure. You'd have to provide a reproducible example. I suspect that reading the documentation for the functions producing `x` and `y`, by typing `?table` etc., would be more helpful than posting such a question, though. Reference on question-asking: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Frank May 12 '15 at 18:20
  • @ChristopherYee. Yes you can with the `aggregate` function like so: `aggregate(list(freq=index_visit$PatientID),by=list(PatientIDs = index_visit$PatientID),FUN=length)` – Jason May 12 '15 at 18:44

0 Answers0