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

相关推荐
golang学习记12 小时前
Go 语言中和类型(Sum Types)的创新实现方案
开发语言·golang
野犬寒鸦12 小时前
Java8 ConcurrentHashMap 深度解析(底层数据结构详解及方法执行流程)
java·开发语言·数据库·后端·学习·算法·哈希算法
兩尛12 小时前
155最小栈/c++
开发语言·c++
百锦再12 小时前
Java IO详解:File、FileInputStream与FileOutputStream
java·开发语言·jvm·spring boot·spring cloud·kafka·maven
Hello.Reader12 小时前
Tauri vs Qt跨平台桌面(与移动)应用选型的“底层逻辑”与落地指南
开发语言·qt·tauri
xyq202412 小时前
R语言连接MySQL数据库的详细指南
开发语言
宇木灵13 小时前
C语言基础-六、指针
c语言·开发语言·学习·算法
百锦再13 小时前
Java InputStream和OutputStream实现类完全指南
java·开发语言·spring boot·python·struts·spring cloud·kafka
mjhcsp13 小时前
C++区间 DP解析
开发语言·c++
danyang_Q13 小时前
vscode python-u问题
开发语言·vscode·python