df <- data.frame( c( 183, 85, 40), c( 175, 76, 35), c( 178, 79, 38 ))
names(df) <- c("Hieght", "Weight", "Age")
Following represents different commands which could be used to extract one or more row with one or more columns. Note that the output is extracted as a data frame. This could be checked using “class” command.
# All Rows and All Columns
df[,]
# First row and all columns
df[1,]
# First two rows and all columns
df[1:2,]
# First and third row and all columns
df[ c(1,3), ]
# First Row and 2nd and third column
df[1, 2:3]
# First, Second Row and Second and Third COlumn
df[1:2, 2:3]
# Just First Column with All rows
df[, 1]
# First and Third Column with All rows
df[,c(1,3)]
Following represents command which could be used to extract a column as a data frame. If you use command such as “df[,1]”, the output will be a numeric vector (in this case). To get an output as a data frame, you would need to use something like below.
# First Column as data frame
as.data.frame( df[,1], drop=false)
Following represents command which could be used to extract an element at a particular row and column. It is as simple as writing a row and a column number such as following:
# Element at 2nd row, third column
df[2,3]
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…