r - Plot a histogram of subset of a data -
!the image shows screen shot of .txt file of data. data consists of 2,075,259 rows , 9 columns
measurements of electric power consumption in 1 household one-minute sampling rate on period of 4 years. different electrical quantities , sub-metering values available.
only data dates 2007-02-01 , 2007-02-02 needed. trying plot histogram of "global_active_power" in above mentioned dates.
note in dataset missing values coded "?"]
this code trying plot histogram:
{ data <- read.table("household_power_consumption.txt", header=true) my_data <- data[data$date %in% as.date(c('01/02/2007', '02/02/2007'))] my_data <- gsub(";", " ", my_data) # replace ";" " " my_data <- gsub("?", "na", my_data) # convert "?" "na" my_data <- as.numeric(my_data) # turn numbers hist(my_data["global_active_power"]) } after running code showing error:
error in hist.default(my_data["global_active_power"]) : invalid number of 'breaks'
can please me spot mistake in code.
link of data file : https://d396qusza40orc.cloudfront.net/exdata%2fdata%2fhousehold_power_consumption.zip
you need provide separator (";") explicitly , types aren't think are, observe:
data <- read.table("household_power_consumption.txt", header=true, sep=';', na.strings='?') data$date <- as.date(data$date, format='%d/%m/%y') bottom.date <- as.date('01/02/2007', format='%d/%m/%y') top.date <- as.date('02/02/2007', format='%d/%m/%y') my_data <- data[data$date > bottom.date & data$date < top.date,3] hist(my_data) gives
plot. hope helps.
Comments
Post a Comment