Indexing and Slicing Data Frames - English
- Questions posted on Forums
- R Tutorials - English
-
Indexing and extracting data
Dear Team ,What should be the syntax when we apply 2 conditions at a time like >20 matches played and less than 14 matches lost ?On writing below commands-print(subData)subData<-subset(Newcaptaincy,played>20,lost<14,select=c("names","played","lost"))print(subData)Answer isprint(subData) names played won1 Dhoni 45 222 Sourav 47 203 Azhar 40 20
11-12M 0-10SMay 14, 2025, 4:06 p.m. Joohi
-
Subset
Can create a two subset at one syntax ? will it disturb all contents of captaincy data frames?Suppose i created as>SubData<-subset(captaincy,played>25,matches<40,select("names","played","lost"))ctrl+sprint(SubData)ctrl+sctrel+enteri have did but unexpected error.
10-11M 20-30SMay 15, 2025, 3:56 p.m. shiksha_saxena
-
data frame slicing
in the assignment my code is subdata <- subset(captaincy,played>20&&lost<14,select =c("names","played","won","lost"))print(subdata)result is names played won lost1 Mahi 45 22 122 Sourav 49 21 133 Azhar 47 14 144 Sunny 47 9 85 Pataudi 40 9 196 Dravid 25 8 6in lost column we have 19 but it should be less than 14 know.
01-02M 0-10SMay 15, 2025, 1:09 p.m. bsankari2007@rediffmail.com
-
Assignment
In the assignment i have worked out got the solution but with an error. Kindly help sirsubData <- subset(captaincy,played>20,lost<14, select = c("names","played","lost")) Error in `[.data.frame`(x, r, vars, drop = drop) : object 'lost' not found > print(subData) names played won 1 Mahi 45 22 2 Sourav 49 21 6 Dravid 25 8
12-13M 30-40SMay 13, 2025, 4:56 p.m. Alamu
-
Got an error on Assignment problem
I am trying to do the assignment but every time I got an error. Please provide me some useful solutionmy code is - subData <- subset(captaincy,played>20,lost<14, select = c("names","played","lost"))print(subData)My ans - names played lost Mahi 45 12 Sourav 49 13 Azhar 47 14 Sunny 47 8 Pataudi 40 19 Dravid 25 6
12-13M 30-40SMay 13, 2025, 8:04 a.m. sumankr545
-
Subset of a Dataset
subdata1<-subset(capataincy,played>20&&lost<14,select = c("names","played","won","lost"))In above query for large dataset can we have another option other than concatenating names of all columns manually?
10-11M 20-30SMay 13, 2025, 10:27 a.m. archanamagare2
-
assignment Operator
Why "<-" operator is more preferred to "=" operator in case of assignment?
07-08M 0-10SMay 15, 2025, 9:48 a.m. judynair
-
1Overview of R and RStudio
-
2Installing R and RStudio on Linux
-
3Installing R and RStudio on Windows
-
4Introduction to basics of R
-
5Introduction to Data Frames in R
-
6Introduction to RStudio
-
7Introduction to R script
-
8Working directories in RStudio
-
Indexing and Slicing Data Frames
-
10Creating Matrices using Data Frames
-
11Operations on Matrices and Data Frames
-
12Merging and Importing Data
-
13Data types and Factors
-
14Lists and its Operations
-
15Plotting Histograms and Pie Chart
-
16Plotting Bar Charts and Scatter Plot
-
17Introduction to ggplot2
-
18Aesthetic Mapping in ggplot2
-
19Data Manipulation using dplyr Package
-
20More Functions in dplyr Package
-
21Pipe Operator
-
22Conditional Statements
-
23Functions in R
Questions posted on ST Forums:
Outline:
Shortcut key for assignment operator (<-) How to perform numeric indexing How to extract a row or column from a data frame How to retrieve multiple rows from a data frame How to combine objects to form a vector How to perform logical indexing on a data frame How to perform name indexing on a data frame How to slice a data frame using subset function How to select required columns (by name) from a data frame How to retrieve data using double square brackets