Aha, yeah a challenge with helping with classwork questions is that when there are many ways to accomplish a task, it’s almost impossible to guess which variation an instructor will have decided to focus on.
A conceptual issue here is whether you want to subset the data frame (as the code you posted does), or whether you want to pull out one of the vectors that makes up the data frame and subset it directly (maybe what your instructor was expecting?). In this case, both methods have the same result:
# Starting with this data frame...
str(File)
#> 'data.frame': 7 obs. of 3 variables:
#> $ Individual: Factor w/ 2 levels "Kent","Mark": 1 2 2 1 1 1 2
#> $ Type : Factor w/ 2 levels "Pistol","Shotgun": 2 1 2 2 1 2 2
#> $ SquareRoot: int 456 753 234 423 894 311 131
# Subset whole data frame (matrix-style)
subset_df <- File[which(File$SquareRoot==median(File$SquareRoot)), "Type"]
subset_df
#> [1] Shotgun
#> Levels: Pistol Shotgun
# Subset just the Type variable
subset_vec <- File$Type[File$SquareRoot == median(File$SquareRoot)]
subset_vec
#> [1] Shotgun
#> Levels: Pistol Shotgun
identical(subset_df, subset_vec)
#> [1] TRUE
The Levels information is printed because your Type variable is a factor. This is the default for text read in from a CSV using read.csv() (although it also would make sense in this case if you were fitting a statistical model to this data). If you must return just a character string, you need to convert the variable or the result:
# Convert result to character
as.character(File$Type[File$SquareRoot == median(File$SquareRoot)])
#> [1] "Shotgun"
# Convert whole Type variable to character
File$Type <- as.character(File$Type)
File$Type[File$SquareRoot == median(File$SquareRoot)]
#> [1] "Shotgun"