[R] to get how many participants in the dataframe and use it

R 复制代码
prop1 <- sum(GE_survey$`Q17_What department are you in` == "HSS") / nrow(GE_survey)
  1. nrow() and ncol() : Suppose you have a dataset my_data that contains information about customers, with each row representing a different customer and each column representing a different attribute (e.g., ID, name, age, etc.). You can use nrow(my_data) to find out how many customers are in the dataset and ncol(my_data) to find out how many attributes each customer record has.

  2. length() : If you have a vector my_vector containing the sales figures for each month of the year, you can use length(my_vector) to find out how many months of sales data you have.

  3. dim() : Suppose you have a matrix my_matrix that represents the results of a survey, with each row representing a different question and each column representing a different respondent. You can use dim(my_matrix) to find out how many questions were asked in the survey and how many respondents answered the survey.

  4. dimnames() : If my_matrix has row and column names indicating the questions and respondent IDs, respectively, you can use dimnames(my_matrix) to access and manipulate these names.

  5. attributes() : If you have a data frame my_df that contains information about products, including their names, prices, and quantities, you can use attributes(my_df) to view or modify the attributes of the data frame, such as its column names or class.

These functions are commonly used in data analysis and manipulation tasks to understand and work with the structure of your data.

相关推荐
闫有尽意无琼13 分钟前
银河麒麟v11 arm编译Qt creator8.0.2报错
开发语言·qt
小此方26 分钟前
从零开始手搓堆:核心操作实现 + 堆排序 + TopK 算法+ 向上调整 vs 向下调整建堆的时间复杂度严密证明!
开发语言·数据结构·算法
_OP_CHEN36 分钟前
从零开始的Qt开发指南:(五)Qt 常用控件之 QWidget(上):解锁 Qt 界面开发的核心基石
开发语言·c++·qt·前端开发·qwidget·gui开发·qt常用控件
wjs202442 分钟前
SQLite 视图
开发语言
q***44811 小时前
java进阶--多线程学习
java·开发语言·学习
艾斯比的日常1 小时前
Neo4j 完全指南:从核心特性到 Java 实战(附企业级应用场景)
java·开发语言·neo4j
后端小张1 小时前
【JAVA 进阶】深入探秘Netty之Reactor模型:从理论到实战
java·开发语言·网络·spring boot·spring·reactor·netty
柠石榴1 小时前
go-1 模型
开发语言·后端·golang
q***d1732 小时前
Rust在网络中的协议栈
开发语言·网络·rust
星释2 小时前
Rust 练习册 88:OCR Numbers与光学字符识别
开发语言·后端·rust