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

3) Create lab02-NOAA . R that reads /u1/junk/cs617/NOAA gsod/1929/030050-99999-1

ID: 3887513 • Letter: 3

Question

3) Create lab02-NOAA . R that reads /u1/junk/cs617/NOAA gsod/1929/030050-99999-1929.op into a data frame using read.fwf. Note that /u1/junk/cs617/NOAA gsod/*.txt describes the data. 3a) Have your program produce a file lab02_NOAA.csv that includes columns: Date, Max Temp, Min Temp, Precip The date should be displayed as "2017-12-31", and Precip should be empty if there was no precipitation that day and "y" if there was precipitation that day. The Precip data is taken from the last column 3b) Have your program also print the number of days, first date, last date, average Min Temp, average Max temp, and percentage of days that had precipitation

Explanation / Answer


##Read file
##Change the path and format according to your data
##Also change width based on your data

input_data<-read.fwf(file="D:/51383795_1502905937997.CSV",widths = c(10,3,3,2))

##Change the column in date format
##Here I have assumed the input in %d/%m/%Y %H:%M:%S" format
##Change it according to your date format

input_data<-mutate(input_data,Date=as.POSIXct(as.POSIXlt.character(Date,format = "%d/%m/%Y %H:%M:%S")))

##Extract the date in the needed format yyyy-mm-dd

input_data$ddate <- format(as.Date(input_data$date), "%Y-%m-%d")

##Create a new column Precip based on the existing column Precipation(I have assumed)
##If na present then put blank else y

input_data<-mutate(input_data,Precip=ifelse(is.na(Precipation),"","y"))

##Extract required columns

input_data<-select(Date,`Max temp`,`Min temp`,Precip)

##Write the data in csv file

write.csv(input_data,"lab022_N0AA.csv")


##Count the number of dates

count_date<-length(input_data$Date)

##First date

first_date<-min(input_data$Date)

##Last date

last_date<-max(input_data$Date)

##Average max temperature

average_max_temp<-mean(input_data$`Max temp`)

##Average min temp

average_min_temp<-mean(input_data$`Min temp`)

##Precipitation_percentage

percentage_of_days<-length(which(input_data$Precip=="y"))/(length(input_data$Precip))

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