Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can somebody help for questions 2? You are given messy.csv containing submission

ID: 3663596 • Letter: C

Question

can somebody help for questions 2?

You are given messy.csv containing submissions for an online form regarding registration for an event. These files contains raw submission from the online from and we want to filter these submissions to only show viable event attendees. Write an R script to generate clean.csv with the constraints listed below. Provide K code for your solution. [Link to DataJoy Template] All attendees must be over 19 and younger than 70 years old Names can only have letters from A-Z and spaces in them Favorite food can be only one of Salad, Pizza, or Pasia Credit card fraud remains a large problem in the online financial

Explanation / Answer

How to Write CSV in R

I often write to CSV with R in order to save data and share files with others. One way to output a csv from R is with the command write.csv. Here is an example of how to write CSV in R:

The above writes the data data frame MyData into a CSV that it creates called MyData.csv. Note that the file is written to your working directory.

Most of the time I don’t want to include row names in the CSV. To omit the row names, I add a comma and then row.names=FALSE. row.names=F will also work if you’re into the whole brevity thing.

Sometimes I also want to leave out the NAs. To omit NAs, add a comma and then na=””.

If you want to leave out the column names it is a little more complicated. write.csv is what is called a “convenience wrapper” and so has few features. Instead, use write.table and specify that sep=”,” and col.names=FALSE.

There are other options that can be used with write.csv. Since write.csv is related to write.table, see official R-manual page on write.table to learn more: http://stat.ethz.ch/R-manual/R-devel/library/utils/html/write.table.html.

Thanks for reading! This website took a great deal of time to create. If it was helpful to you, please show it by sharing with friends, liking, or tweeting! If you have any thoughts regarding this R code please post in the comments.

Writing data to a file

Problem

You want to write data to a file.

Solution

Writing to a delimited text file

The easiest way to do this is to use write.csv(). By default, write.csv() includes row names, but these are usually unnecessary and may cause confusion.

Saving in R data format

write.csv() and write.table() are best for interoperability with other data analysis programs. They will not, however, preserve special attributes of the data structures, such as whether a column is a character type or factor, or the order of levels in factors. In order to do that, it should be written out in a special format for R.

Below are are three primary ways of doing this:

The first method is to output R source code which, when run, will re-create the object. This should work for most data objects, but it may not be able to faithfully re-create some more complicated data objects.

The next method is to write out individual data objects in RDS format. This format can be binary or ASCII. Binary is more compact, while ASCII will be more efficient with version control systems like Git.

It’s also possible to save multiple objects into an single file, using the RData format.

An important difference between saveRDS() and save() is that, with the former, when you readRDS() the data, you specify the name of the object, and with the latter, when you load() the data, the original object names are automatically used. Automatically using the original object names can sometimes simplify a workflow, but it can also be a drawback if the data object is meant to be distributed to others for use in a different environment.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote