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

相关推荐
mmsx44 分钟前
Android Dialog 插槽模式:用一套壳统一全应用的弹窗风格
android·java·dialog·开发语言
huanbailu1 小时前
Qt 跨线程信号槽:connect 返回 true 但槽函数不执行的坑
开发语言·c++·qt·信号槽·跨线程·元类型
ZealSinger1 小时前
Go slog生产落地LevelVar与共存
开发语言·后端·golang·go
落魄实习生1 小时前
Agent Scope Java 2.x 系列【11】AgentState 与状态存储
java·开发语言·ai
HEJOO91 小时前
C++ 虚函数表(vtable)深度解析
开发语言·c++
老王爱玩车1 小时前
深入理解指针5
c语言·开发语言·学习
丹宇码农1 小时前
Go 与 Python 协程(Coroutine)对比演示项目
开发语言·python·golang
ttwuai2 小时前
Go开源后台管理系统推荐:3个官方仓库怎么按技术栈和适用边界比较?
开发语言·golang·开源
个 人 练 习 生2 小时前
C++-----string基本使用详解
开发语言·c++·学习
朝朝辞暮i2 小时前
C++ 第 5 课:else if + 多条件判断 + && / || / !
开发语言·c++