[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 分钟前
Go 语言测试综合指南
开发语言·golang·log4j
froginwe113 分钟前
《Viewport》详解:网页布局中的核心概念
开发语言
量子炒饭大师5 分钟前
【C++入门】Cyber尖层的虚实重构—— 【类与对象】类型转换
开发语言·c++·重构·类型转换·隐式转换·explicit·类与对象
wula199410 分钟前
C# Revit二次开发 地层工程量统计
开发语言·c#
范特西.i13 分钟前
QT聊天项目(4)
开发语言·qt
lly20240613 分钟前
PostgreSQL DELETE 操作详解
开发语言
今天你TLE了吗17 分钟前
JVM学习笔记:第二章——类加载子系统
java·开发语言·jvm·笔记
AutumnorLiuu18 分钟前
C++并发编程学习(四)——死锁及其预防
开发语言·c++·学习
_OP_CHEN24 分钟前
【前端开发之JavaScript】(二)JS基础语法上篇:吃透变量 / 类型 / 输入输出
开发语言·javascript·html·ecmascript·前端开发·网页开发
Maguyusi25 分钟前
go 批量生成 c++与lua的proto文件
开发语言·后端·golang·protobuf