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

相关推荐
网安_秋刀鱼几秒前
【java安全】URL链拆解
java·开发语言·安全·web安全·网络安全
ht巷子几秒前
Qt:容器类
开发语言·c++·qt
云老大TG:@yunlaoda3601 分钟前
华为云国际站代理商的DDM的跨境部署调优是如何实现的?
开发语言·数据库·华为云·php
_OP_CHEN2 分钟前
【从零开始的Qt开发指南】(十三)Qt 窗口之菜单栏完全攻略:从入门到实战,打造专业级桌面应用菜单系统
开发语言·qt·前端开发·图形化界面·菜单栏·gui开发·qt窗口
superman超哥6 分钟前
仓颉协程调度机制深度解析:高并发的秘密武器
c语言·开发语言·c++·python·仓颉
你不是我我13 分钟前
【Java 开发日记】我们来说一下 synchronized 与 ReentrantLock 的区别
开发语言·c#
平常心cyk14 分钟前
C++ 继承与派生知识点详解
开发语言·c++
charlie11451419118 分钟前
嵌入式现代C++:何时用 C++、用哪些 C++ 特性(折中与禁用项)
开发语言·c++·笔记·学习
山峰哥1 小时前
Python爬虫实战:从零构建高效数据采集系统
开发语言·数据库·爬虫·python·性能优化·架构
郝学胜-神的一滴2 小时前
使用OpenGL绘制卡通效果的圣诞树
开发语言·c++·程序人生·游戏·图形渲染