Skip to content

Instantly share code, notes, and snippets.

@Ehsan1997
Last active March 18, 2017 18:02
Show Gist options
  • Save Ehsan1997/d3416816cbd376e1d5992c35549316f4 to your computer and use it in GitHub Desktop.
Save Ehsan1997/d3416816cbd376e1d5992c35549316f4 to your computer and use it in GitHub Desktop.
Annalyzing data using R
#Author : Muhammad Ehsan ul Haq
#Read the data from the text file
dataAlpha = read.table("dataAlpha.txt", header = TRUE)
dataBravo = read.table("dataBravo.txt", header = TRUE)
#number of no-responses
noResponseAlpha = sum(dataAlpha == -1)
noResponseBravo = sum(dataBravo == -1)
print(sprintf("Number of no Responses in Alpha = %d", noResponseAlpha))
print(sprintf("Number of no Responses in Bravo = %d", noResponseBravo))
#finding standard deviation
sdAlpha = sd(unlist(dataAlpha["RTT"]))
sdBravo = sd(unlist(dataBravo["RTT"]))
print(sprintf("Standard Deviation of RTT of Alpha = %f", sdAlpha))
print(sprintf("Standard Deviation of RTT of Bravo = %f", sdBravo))
#finding mean of the data
mAlpha = mean(unlist(dataAlpha["RTT"]))
mBravo = mean(unlist(dataBravo["RTT"]))
print(sprintf("Mean of RTT of Alpha = %f", mAlpha))
print(sprintf("Mean of RTT of Bravo = %f", mBravo))
#plotting the data
plot(data.frame(dataAlpha["StartTime"], dataAlpha["RTT"]), "Time", type = "p", main = "Alpha")
plot(data.frame(dataBravo["StartTime"], dataBravo["RTT"]), "Time", type = "p", main = "Bravo", col = "red")
plot(data.frame(dataAlpha["StartTime"], dataAlpha["RTT"]), "Time", type = "p", main = "Alpha and Bravo")
points(data.frame(dataBravo["StartTime"], dataBravo["RTT"]), pch = 4, col = "red")
legend("topright", legend = c("Alpha", "Bravo"), col = c("black", "red"), pch = c(1, 4), cex = 0.6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment