TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW02.5

Aus VoWi
Zur Navigation springen Zur Suche springen
R-functions

trees is the R Dataset Package containing Diameter, Height and Volume for 31 Black Cherry trees. Using R define a vector h that contains the values of the column Height and define a vector v that contains the values of the column Volume from the dataset trees. Use the command table(h) to obtain the frequency table of the vector h. What are the outputs of the commands summary(h) and factor(h)? Compute the sample means mean() and the sample

variances var() for both vectors. Use the command plot() to plot the points .

Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)


Lösungsvorschlag von Lessi[Bearbeiten | Quelltext bearbeiten]

--Lessi 2024-02-07T13:04:11Z

attach(trees)
h <- as.double(Height)
v <- Volume

# obtain the frequency table of the vector h
freq <- table(h)
freq

# outputs of the commands summary(h) and factor(h)
summary(h) # summarizes the sample based on p-quantile, min, max, mean, median

factor(h) # what are the distinct values of h "Werteausprägungen"

# Compute the sample means mean() and the sample variances var() for both vectors
mean(h) # sum(h) / length(h)
var(h) # degree of spread (how far away from mean)
mean(v) 
var(v) 

# Use the command plot() to plot the points (h, v).

plot(h, v, main="Trees", col="red")