I'm not totally sure what you are having problems with, but I am assuming that since you seem to have been able to execute library(tidyverse)
, that you know how to execute the code, and what you're looking for is ways to view the contents of the dataframe.
library(tidyverse)
names <- c("sara", "jess","jack", "iga")
age <- c(65, 6, 98, 4)
people <- data.frame(names, age)
Created on 2023-10-10 with reprex v2.0.2
As long as you've executed the lines there to assign the values to names and age, they should show up on the right side in RStudio in the Environment section, and you should be able to see their structure and some of their contents at a glance.
However, if you want to see all of what is inside them, there are a few ways to do so.
The first, is if you want to quickly check the contents, you can highlight the object or dataframe you've created, and while it is highlighted, you can run it (otherwise know as executing it).
Otherwise, you can also write the object out by itself on a new line, or you can use one of a few functions to output it.
names
#> [1] "sara" "jess" "jack" "iga"
age
#> [1] 65 6 98 4
people
#> names age
#> 1 sara 65
#> 2 jess 6
#> 3 jack 98
#> 4 iga 4
Here, we can see the results if you just execute the name of the object or dataframe.
However, below are a few examples of functions you can use to help with printing out the contents of a dataframe. The first two are print() and head(), which are fairly standard methods for printing, and for both of these, you can specify a number of rows/values within that you want to show. This can be helpful when you start getting into really large datasets and don't want to get overwhelmed with thousands of rows.
The next function is writeLines() which is similar, but writeLines does a little more under the hood to format whatever it is given based on what type of object it is. For example, we can see that it put each name on its own line. However, this can only be used with character objects, so it won't be as helpful with the other two you're trying to output.
print(names)
#> [1] "sara" "jess" "jack" "iga"
writeLines(names)
#> sara
#> jess
#> jack
#> iga
head(names)
#> [1] "sara" "jess" "jack" "iga"
print(age)
#> [1] 65 6 98 4
head(age)
#> [1] 65 6 98 4
print(people)
#> names age
#> 1 sara 65
#> 2 jess 6
#> 3 jack 98
#> 4 iga 4
head(people)
#> names age
#> 1 sara 65
#> 2 jess 6
#> 3 jack 98
#> 4 iga 4
head(people, n = 2L)
#> names age
#> 1 sara 65
#> 2 jess 6
I hope this helped!