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

相关推荐
CoderYanger3 小时前
Java EE 进阶:12.Spring AOP(第一弹)
java·开发语言·spring boot·后端·spring·java-ee·交互
松仔log3 小时前
Kotlin中级——KMP
android·开发语言·kotlin
H H.4 小时前
Java笔记:String字符串
java·开发语言·经验分享·笔记·其他
鲸渔4 小时前
【AI Agent系列课程26-Python 基础26】复盘:Python 接口开发知识清单
开发语言·python·ai编程
sharemylove4 小时前
Java 异常处理 学习笔记
java·开发语言·经验分享·笔记·学习
西西弗Sisyphus4 小时前
Qt QML 程序是怎么跑起来的(1)qml-only
开发语言·c++·qt
码途行者6 小时前
每天10分钟学Go:第21课 错误
开发语言·后端·golang
sharemylove6 小时前
Java 常用类 学习笔记
java·开发语言·经验分享·笔记·学习
多加点辣也没关系16 小时前
JavaScript|第41章:性能优化实战
开发语言·javascript·性能优化
Resean022316 小时前
架构设计系列(十六):DDD 与代码架构
java·开发语言·架构