Below are two equivalent solutions. study_df <- data.frame(course = c(rep('Mathematics', 80 + 15), rep('Physics', 32 + 24), rep('Biology', 18 + 29)), A = c(rep(1, 80), rep(0, 15), rep(1, 32), rep(0, 24), rep(1, 18), rep(0, 29)))
and my_courses <- c(rep('Mathematics', 80 + 15), rep('Physics', 32 + 24), rep('Biology', 18 + 29)) my_A <- c(rep(1, 80), rep(0, 15), rep(1, 32), rep(0, 24), rep(1, 18), rep(0, 29)) study_df <- data.frame(course = my_courses, A = my_A) R. Mark Sharp msh...@txbiomed.org<mailto:msh...@txbiomed.org> On May 15, 2012, at 2:09 PM, T Bal wrote: Hello, My data is "study.txt": "A" "Not A" "Mathematics" 80 15 "Physics" 32 24 "Biology" 18 29 I want to transform this data into with column names 'course' and 'A': course A 1 Mathematics 1 2 Mathematics 1 .. ...... .. 80 Mathematics 1 81 Mathematics 0 ... ............ ... 95 Mathematics 0 96 Physics 1 ... ............ ... 127 Physics 1 128 Physics 0 ... ............ ... 151 Physics 0 etc. How should I do it? So this data frame will consist from 198 rows. Thank you very much. kind regards, T. Bal [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org<mailto:R-help@r-project.org> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.