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

相关推荐
mqiqe10 小时前
线程调度与 Schedulers:Project Reactor 并发模型的核心引擎
java·开发语言·网络
xixiaoyunya11 小时前
JavaScript 异步编程全解析:从回调地狱到 async/await 的演进之路
开发语言·javascript·ecmascript
精英的英11 小时前
记一次 Qt5 Language Server 开发
开发语言·vscode·qt
烧酒同学12 小时前
【C++】记录size of std::vector的巧妙坑
开发语言·c++·图形渲染
周周哈哈哈12 小时前
线程创建、执行、退出、回收
java·开发语言
gb421528712 小时前
python中Web应用服务器
开发语言·前端·python
萧瑟余晖13 小时前
Java深入解析篇三十六之分布式系统详解
java·开发语言·分布式
ZJU_统一阿萨姆13 小时前
【推理优化进阶】调度器的数学内核:排队论、SLO 与在线决策
开发语言·人工智能·语言模型·系统架构·vllm
两个人的幸福online13 小时前
PHP 实现国密 SM3 踩坑记录:HMAC-SM3 签名对接 CNR 接口
开发语言·php
SomeB1oody14 小时前
【RustyML入门】5.2. 分类指标
开发语言·后端·机器学习·rust·教程