Re: [R] question about creating data frame

2012-06-14 Thread Mark Sharp
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),

Re: [R] question about creating data frame

2012-05-15 Thread jim holtman
try this: > x <- read.table(text = '"Not A" "A" + "Mathematics" 80 15 + "Physics" 32 24 + "Biology" 18 29', skip = 1, as.is = TRUE) > > # create the result > result <- do.call(rbind, lapply(1:nrow(x), function(.row){ + data.frame(course = x$V1[.row] + , A = c(rep(1, x$V2[.row]), rep(0

[R] question about creating data frame

2012-05-15 Thread T Bal
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 Mathem

[R] question about creating data frame

2012-05-15 Thread T Bal
Hello, My data is "study.txt": "Not A" "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