[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.

相关推荐
半个番茄2 小时前
C 或 C++ 中用于表示常量的后缀:1ULL
c语言·开发语言·c++
玉带湖水位记录员2 小时前
状态模式——C++实现
开发语言·c++·状态模式
Eiceblue4 小时前
Python 合并 Excel 单元格
开发语言·vscode·python·pycharm·excel
jerry2011084 小时前
R语言学习笔记之高效数据操作
r语言
SomeB1oody5 小时前
【Rust自学】15.2. Deref trait Pt.1:什么是Deref、解引用运算符*与实现Deref trait
开发语言·后端·rust
情深不寿3175 小时前
C++----STL(list)
开发语言·c++
SomeB1oody6 小时前
【Rust自学】15.4. Drop trait:告别手动清理,释放即安全
开发语言·后端·rust
liruiqiang056 小时前
DDD-全面理解领域驱动设计中的各种“域”
开发语言·架构
前端熊猫6 小时前
JavaScript 的 Promise 对象和 Promise.all 方法的使用
开发语言·前端·javascript
weixin_421133417 小时前
编写python 后端 vscode 安装插件大全
开发语言·vscode·python