GithubHelp home page GithubHelp logo

datasciencecoursera's Introduction

datasciencecoursera

No.1

    pollutantmean <- function(directory, pollutant, ID = 1:332){
    
    # Get file names from directory argument
    files_list <- list.files(directory, full.names = TRUE)
    
    # Create a single data frame from all of the files
    dat <- lapply(files_list,
                  read.csv)
    dat <- do.call("rbind", dat)
    
    # Subset the data appropriately
    dat_subset <- dat[dat$ID %in% ID, ]
    
    # Get the mean of the two columns, return in a list
    lapply(dat_subset[c("nitrate", "sulfate")],
           mean,
           na.rm = TRUE)
    }

No 2

    complete <- function(directory, id = 1:332) {

    cvsfiles <- list.files(directory, full.names=TRUE)
    
    nobs <- c()
    for (i in id) {
            dat <- read.csv(files_list[i])
            nobs <- c(nobs, sum(complete.cases(dat)))
            }
    data.frame(id,nobs)
    
    }

    complete("specdata", 30:25)

No 3

    source("complete.R")
    corr <- function(directory, threshold = 0) {
    
    result <- numeric()
    
    # Get file names from directory argument
    files_list <- list.files(directory, full.names = TRUE)
    
    complete_df <- complete(directory)
    
    # subset rows that have number of observations greater than `threshold`
    usable_df <- complete_df[complete_df$nobs > threshold,]
    
    for(monitor_id in usable_df$id) {
            # read data frame for monitors past the threshold
            path <- sprintf("%s/%03d.csv", directory, monitor_id)
            df <- read.csv(path, header = TRUE, comment.char = "")
            
            correlation <- cor(x = df$sulfate, y = df$nitrate, use = "complete.obs")
            result <- c(result, correlation)
            }
    result
    }

    cr <- corr("specdata", 400)
    head(cr)

datasciencecoursera's People

Contributors

maureenmao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.