Write a R program to create a data frame from four given vectors.
name = c('Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas') score = c(12.5, 9, 16.5, 12, 9, 20, 14.5, 13.5, 8, 19) attempts = c(1, 3, 2, 3, 2, 3, 1, 1, 2, 1) qualify = c('yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes') print("Original data frame:") print(name) print(score) print(attempts) print(qualify) df = data.frame(name, score, attempts, qualify) print(df)
Sample Output:
[1] "Original data frame:" [1] "Anastasia" "Dima" "Katherine" "James" "Emily" "Michael" [7] "Matthew" "Laura" "Kevin" "Jonas" [1] 12.5 9.0 16.5 12.0 9.0 20.0 14.5 13.5 8.0 19.0 [1] 1 3 2 3 2 3 1 1 2 1 [1] "yes" "no" "yes" "no" "no" "yes" "yes" "no" "no" "yes" name score attempts qualify 1 Anastasia 12.5 1 yes 2 Dima 9.0 3 no 3 Katherine 16.5 2 yes 4 James 12.0 3 no 5 Emily 9.0 2 no 6 Michael 20.0 3 yes 7 Matthew 14.5 1 yes 8 Laura 13.5 1 no 9 Kevin 8.0 2 no 10 Jonas 19.0 1 yes
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
[1] "Original data frame:" [1] "Anastasia" "Dima" "Katherine" "James" "Emily" "Michael" [7] "Matthew" "Laura" "Kevin" "Jonas" [1] 12.5 9.0 16.5 12.0 9.0 20.0 14.5 13.5 8.0 19.0 [1] 1 3 2 3 2 3 1 1 2 1 [1] "yes" "no" "yes" "no" "no" "yes" "yes" "no" "no" "yes" name score attempts qualify 1 Anastasia 12.5 1 yes 2 Dima 9.0 3 no 3 Katherine 16.5 2 yes 4 James 12.0 3 no 5 Emily 9.0 2 no 6 Michael 20.0 3 yes 7 Matthew 14.5 1 yes 8 Laura 13.5 1 no 9 Kevin 8.0 2 no 10 Jonas 19.0 1 yesneed an explanation for this answer? contact us directly to get an explanation for this answer