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),
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
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
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
4 matches
Mail list logo