data manipulations with group_by lost when exporting?

I created a small script to sort the data exactly the way I wanted for my school. I import a dataset from the school which contains students and their grades. I am then grouping by their first and last name so that I get a line of student data with their class names and grades. The summarize function worked perfection on the screen, and then I went to export this data and when I did using write_csv() it just exporting the un-sorted version of the file.

Here's my code:

cnames <- c("cid", "cname", "sid", "fname", "lname", "overall_percent", "overall_grade", "average_points", "weighted_score")
tdata <- read_csv("2020 - 2021 semester 1.csv", col_types = "dccccicii", col_names = cnames)
head(tdata)
fdata <- drop_na(tdata)
ndata <- fdata %>% group_by(fname, lname)
ndata %>%
summarize(Class_name = cname, GPA = overall_percent, Letter_grade = overall_grade)
ndf_data <- as_tibble(ndata) %>%
write_csv("TFLS data from R.csv")

I'm new to R, but love its ability to help me analyze this data, and it's so powerful and easy, but I just don't know why I can't export the sorted dplyr data. My next step will be to try and separate by the names and create reports of each individual student in the list with their grades on a single sheet of paper. Any ideas on packages that could easily handle this?

Thanks for any help with this.

You do not store the result of

ndata %>%
summarize(Class_name = cname, GPA = overall_percent, Letter_grade = overall_grade)

Perhaps you should use

ndata <- ndata %>%
summarize(Class_name = cname, GPA = overall_percent, Letter_grade = overall_grade)

as_tibble(ndata) %>%
write_csv("TFLS data from R.csv")

There is no need to store the result of write.csv(). You use that function for its side effect of writing out the data. I am not sure what you gain by using as_tibble() in that last line but I may be missing something.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you. This did the trick. The as_tibble line was where I was attempting to save the results, but obviously got confused there.