I am trying to subset my data and for the life of me I cannot figure out why this isn't working. Here's a link to my data, which is a csv file Data. I've tried these ways to subset, but they all just create a header with no observations.
alveolar.df <- combine.df[combine.df$articulation == "velar_coronal", ]
alveolar.df <- subset(combine.df, articulation == "velar_coronal")
alveolar.df <- combine.df[combine.df$articulation %in% c("velar_coronal"), ]
Here is a sample of the data -
combine.df <- structure(list(start = c(215.76, 278.78, 862.35, 1050.22, 512.59,
552.97), end = c(217.18, 280.68, 863.85, 1051.72, 515.02, 555.67
), articulation = c(" velar_coronal", " velar_labial", " velar_coronal",
" velar_coronal", " velar_coronal", " velar_coronal"), hometown = structure(c(1L,
NA, 2L, 3L, 4L, 4L), .Label = c(" Montana ", " ", " San Leandr ",
" Southern California "), class = "factor")), .Names = c("start",
"end", "articulation", "hometown"), row.names = c(NA, 6L), class = "data.frame")
You have extra whitespace in the column, which is why you are getting all FALSE results from the logical expression and hence no rows in your subset. Notice the extra space at the beginning of each string below.
combine.df$articulation
# [1] " velar_coronal" " velar_labial" " velar_coronal" " velar_coronal"
# [5] " velar_coronal" " velar_coronal"
combine.df$articulation == "velar_coronal"
# [1] FALSE FALSE FALSE FALSE FALSE FALSE
You actually have this issue in more than one column. You can do either of these two things:
Use strip.white = TRUE when you originally read the data into R (assuming you used read.csv() or read.table())
Use the new trimws() function in base R to trim the excess whitespace from the column
combine.df$articulation <- trimws(combine.df$articulation)
and then try your code again.
The better method would be the first, to go back and read the data in again, using strip.white = TRUE since this will assure no extra whitespace in any column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With