What is the equivalent of iloc and ix in R?

I have a data set with column names X and Y; once I load the data to a dF; how do I get a data frame containing only values of dF with X = A (lets say A is one of the values of X).

I get this error when I try df$var_Structure=="A" in R Studio console - https://itsmycode.com/object-of-type-closure-is-not-subsettable/#:~:text=What%20does%20object%20of%20type,the%20name%20instead%20of%20value.;

I forgot how to use slice here

Here are two methods for picking rows where column X == "A".

DF <- data.frame(X=c("A","B","A","B"),y=1:4)
DF
#>   X y
#> 1 A 1
#> 2 B 2
#> 3 A 3
#> 4 B 4

#Method1
DF2 <- DF[DF$X=="A",]
DF2
#>   X y
#> 1 A 1
#> 3 A 3

#method2
library(dplyr)
DF3 <- filter(DF,X=="A")
DF3
#>   X y
#> 1 A 1
#> 2 A 3

Created on 2022-09-21 with reprex v2.0.2

This topic was automatically closed 42 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.