What is the and operator for a character?

I have a csv. One of the headers is "SiteDate". Using the summary function, I want to only include PCJ_17jul21, BCV_20aug21,LCV_20aug21 and BCT_03aug21. R recognizes these as characters. I tried:

summer.irr<- irr.norm%>%filter(SiteDate=="PCJ_17jul21" & "BCV_20aug21"&"LCV_20aug21"& "BCT_03aug21"

I also tried the or operator. I get an error saying these operators can only be used for numeric data.

Help and thanks!

summer.irr <- irr.norm %>% filter(SiteDate %in% c("PCJ_17jul21" , 
                                                  "BCV_20aug21", 
                                                  "LCV_20aug21", 
                                                  "BCT_03aug21"))

Hmm... this didn't give me an error. But now, I have no data... In my environment summer_irr is "0 obs. of 4 variables".

Post your data, or at least some of it. Perhaps use dput().

dput() gives way too much info. Here is a pic. So every SiteDate has a norm_irr and norm_irr_equal_area for every wavelength 300-800ish.

Try something like, dput(head(yourdf, 20)) This will show the first 20 rows to us.

dput(head(Irr_norm,20))
structure(list(SiteDate = c("BC-T Aug_18_2020", "BC-T Aug_18_2020",
"BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020",
"BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020",
"BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020",
"BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020", "BC-T Aug_18_2020",
"BC-T Aug_18_2020", "BC-T Aug_18_2020"), wavelength = c(300,
301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319), Norm_irr = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Norm_irr_equal_area = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L), groups = structure(list(
SiteDate = "BC-T Aug_18_2020", .rows = structure(list(1:20), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L), .drop = TRUE))

Thanks everyone. I am so new to R and I have a my first thesis committee meeting soon... I gotta make sense of this data.

Very helpful. Your data has things like "BC-T Aug_18_2020" and you are looking for things like "BCT_03aug21" They don't match.

In my acutal code that I ran I made sure they matched:
summer_irr<-Irr_norm%>%filter(SiteDate%in% c("LCV-V 24Jul20","B-CV 24Jul20","B-CT Aug_18_2020","P-CJ Aug_22_2020"))

Try this to see all the levels

library(tidyverse)
Irr_norm %>%
   distinct(SiteDate)

You might have some "trivial" error in the code you aren't showing us. Using your dput() I did

> lrr_norm %>% filter(SiteDate %in% c("BC-T Aug_18_2020"))
# A tibble: 20 x 4
# Groups:   SiteDate [1]
   SiteDate         wavelength Norm_irr Norm_irr_equal_area
   <chr>                 <dbl>    <dbl>               <dbl>
 1 BC-T Aug_18_2020        300        0                   0
 2 BC-T Aug_18_2020        301        0                   0
 3 BC-T Aug_18_2020        302        0                   0
 4 BC-T Aug_18_2020        303        0                   0
 5 BC-T Aug_18_2020        304        0                   0
 6 BC-T Aug_18_2020        305        0                   0
 7 BC-T Aug_18_2020        306        0                   0
 8 BC-T Aug_18_2020        307        0                   0
 9 BC-T Aug_18_2020        308        0                   0
10 BC-T Aug_18_2020        309        0                   0
11 BC-T Aug_18_2020        310        0                   0
12 BC-T Aug_18_2020        311        0                   0
13 BC-T Aug_18_2020        312        0                   0
14 BC-T Aug_18_2020        313        0                   0
15 BC-T Aug_18_2020        314        0                   0
16 BC-T Aug_18_2020        315        0                   0
17 BC-T Aug_18_2020        316        0                   0
18 BC-T Aug_18_2020        317        0                   0
19 BC-T Aug_18_2020        318        0                   0
20 BC-T Aug_18_2020        319        0                   0

which seems to work fine.

EUREKA! THANK YOU SO MUCH. You were right. My names didn't match 100%. Goodness, in R it can be so easy to get lost in your data. Sometimes you just need someone from the outside to look at it too. This is all so new to me and this community has been so helpful and kind.

Let's just say that the longer one's been doing this the more mistakes one has already made :smile: :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.