Show the code
## Set read_csv function option to suppress warning messages.
options(readr.show_col_types = FALSE)
## Use the package for the read_csv function
library(tidyverse)
library(readr)
## Data input.
data <- read_csv(col_names=TRUE, file=
"name, age, marital_status, children, education, farm_size, crop, organic, factory_work
Bill, 62, married, 2, Secondary, 128, corn, no, no
Harry, 23, single, 0, Tertiary, 5, mustard, yes, yes
Fred, 52, single, 0, Tertiary, 180, corn, no, no
Sam, 34, married, 5, Secondary, 45, soybeans, yes, yes
Jim, 51, married, 2, Secondary, 50, corn, yes, no
Frank, 29, married, 1, Tertiary, 30, soybeans, yes, yes
Carl, 73, widower, 2, Secondary, 300, corn, no, no
Pete, 33, married, 3, Secondary, 40, mustard, no, no
John, 60, single, 0, Secondary, 10, soybeans, no, yes
Philip, 41, married, 1, Tertiary, 40, mustard, no, yes
Ben, 39, married, 3, Tertiary, 50, soybeans, yes, no
Richard,53, single, 0, Primary, 30, soybeans, yes, no
Don, 59, married, 2, Secondary, 60, mustard, no, no
James, 51, married, 4, Tertiary, 3, soybeans, no, yes
Chris, 43, married, 2, Secondary, 23, corn, no, yes
Bob, 56, divorced, 3, Tertiary, 40, soybeans, no, no
Joe, 64, married, 2, Secondary, 120, soybeans, yes, no
Max, 32, married, 0, Tertiary, 30, corn, no, yes
Dave, 36, married, 4, Tertiary, 10, corn, yes, yes
Erik, 29, single, 0, Tertiary, 30, soybeans, yes, no
Ed, 81, single, 0, Secondary, 50, soybeans, no, no
Roger, 53, married, 3, Secondary, 60, corn, yes, no")
## Save the input data as a CSV file
write_csv(data, "farmers_data.csv")
## Display the data
data
# A tibble: 22 × 9
name age marital_status children education farm_size crop organic
<chr> <dbl> <chr> <dbl> <chr> <dbl> <chr> <chr>
1 Bill 62 married 2 Secondary 128 corn no
2 Harry 23 single 0 Tertiary 5 mustard yes
3 Fred 52 single 0 Tertiary 180 corn no
4 Sam 34 married 5 Secondary 45 soybeans yes
5 Jim 51 married 2 Secondary 50 corn yes
6 Frank 29 married 1 Tertiary 30 soybeans yes
7 Carl 73 widower 2 Secondary 300 corn no
8 Pete 33 married 3 Secondary 40 mustard no
9 John 60 single 0 Secondary 10 soybeans no
10 Philip 41 married 1 Tertiary 40 mustard no
# ℹ 12 more rows
# ℹ 1 more variable: factory_work <chr>