art.frame
Problem to Solve
You’ve learned about data frames: objects for storing data in rows and columns. In a file called art.R
in a folder called art.frame
, practice using data frames to create your very own art in R.
Demo
Background
You’ve learned how to create a data frame by reading data from a file. Turns out you can also create your own data frames from scratch, using a function called data.frame
.
Per its documentation, data.frame
can be provided any number of named arguments. Those argument names become the data frame’s column names. Then, the values for each of those arguments become the given column’s values.
Take a look at how you could create a small, 3x3 data frame:
data.frame(
A = c("1", "2", "3"),
B = c("4", "5", "6"),
C = c("7", "8", "9")
)
Notice that there are 3 named arguments: A
, B
, and C
. Each is passed a different value—a vector of 3 numbers!
Curious about c
?
c
is a function that creates a vector from a list of elements, separated by commas.
The above code produces a data frame like the below:
A | B | C | |
---|---|---|---|
1 | 1 | 4 | 7 |
2 | 2 | 5 | 8 |
3 | 3 | 6 | 9 |
Consider both widening and lengthening your data frame, as well as filling each column with a vector of empty spaces:
data.frame(
A = c(" ", " ", " ", " ", " "),
B = c(" ", " ", " ", " ", " "),
C = c(" ", " ", " ", " ", " "),
D = c(" ", " ", " ", " ", " "),
E = c(" ", " ", " ", " ", " ")
)
You now have a blank canvas with which to create your art!
Distribution Code
For this problem, you’ll need to create art.R
in a folder called art.frame
.
Create art.R
Open RStudio per the linked steps and navigate to the R console:
>
Next execute
getwd()
to print your working directory. Ensure your current working directory is where you’d like to create this problem’s folder. If using RStudio through cs50.dev the recommended directory is /workspaces/NUMBER
where NUMBER
is a number unique to your codespace.
If you do not see the right working directory, use setwd
to change it!
Next execute
dir.create("art.frame")
in order to create a folder called art.frame
in your codespace.
Now type
setwd("art.frame")
followed by Enter to move yourself into (i.e., open) that directory. Your working directory should now end with
art.frame/
Finally, type
file.create("art.R")
to create a file called art.R
inside of the art.frame
folder.
If all was successful, you should execute
list.files()
and see art.R
. If not, retrace your steps and see if you can determine where you went wrong!
To start on this problem, copy and paste the below code into art.R
:
art <- data.frame(
A = c(" ", " ", " ", " ", " "),
B = c(" ", " ", " ", " ", " "),
C = c(" ", " ", " ", " ", " "),
D = c(" ", " ", " ", " ", " "),
E = c(" ", " ", " ", " ", " ")
)
print(art)
Specification
Modify the data frame stored as art
to make art of your choice. You have creative freedom to:
- Add rows and columns
- Rename columns
Consider avoiding emoji: when printed, they appear wider than other characters and will break the vertical alignment of your columns. 🙁
The only specifications you must adhere to are the following:
- You should store your data frame using an object called
art
. - You should print your data frame at the end of your program.
- Your data frame should contain at least 3 rows and 3 columns.
Usage
Assuming art.R
is in your working directory, enter the below in the R console to test your program:
source("art.R")
Assessment
See the feedback page to learn more about how problems like these will be assessed.
Correctness
While check50
is available for this problem (see below), you’re encouraged to test your code on your own by running your program frequently.
check50
You can check your code using check50
, a program that CS50 will use to test your code when you submit. But be sure to test it yourself as well!
Run the following command in the R Studio console:
check50("cs50/problems/2025/r/art.frame")
Green smilies mean your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that check50 outputs to see the input check50 handed to your program, what output it expected, and what output your program actually gave.
How to Submit
After you submit, be sure to check your autograder results. If you see SUBMISSION ERROR: missing files (0.0/1.0)
, it means your file was not named exactly as prescribed (or you uploaded it to the wrong problem).
Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting files with the correct name. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames for you after the fact!
In RStudio, select the art.R
file containing your work for this problem, as by checking the box to the left of the file’s name. With the file selected, click on the icon at the top of the file explorer. Choose Export followed by Download.
Go to CSCI E-5a’s Gradescope page.
Click Problem Set 1: art.frame.
Drag and drop your .R
file to the area that says Drag & Drop. Be sure that your .R
file is correctly named exactly as prescribed above, lest the autograder fail to run on your submission! Note that your submission is considered incomplete if any of the files are missing—be sure they’re all there!
Click Upload.
You should see a message that says “Problem Set 1: art.frame submitted successfully!”
Be sure to double-check your autograder results before moving on!