call(c, listoflists) all.equal(listofvectors, res, check.attributes = FALSE) #[1] TRUE 或者正如@d.b在评论中提到的,带有recursive = FALSE的unlist也可以工作 代码语言:javascript 复制 unlist(listoflists, recursive = FALSE) 收藏分享票数21 EN Stack Overflow用户 发布于 2017-04-08 11:30:45 对...
# Create two lists. list1 <- list(1,2,3) list2 <- list("Sun","Mon","Tue") # Merge the two lists. merged.list <- c(list1,list2) 1. 2. 3. 4. 5. 6. 7. 转换列表为向量 # Convert the lists to vectors. v1 <- unlist(list1) 1. 2. 条件语句 if(checkConditionIfTrue) ...
使用unname()删除顶级列表的名称,然后再执行unlist()操作。
使用unname()删除顶级列表的名称,然后再执行unlist()操作。
list_data <- list(c("Jan","Feb","Mar"), matrix(c(3,9,5,1,-2,8), nrow = 2), list("green",12.3)) Give names to the elements in the list. names(list_data) <- c("1st Quarter", "A_Matrix", "A Inner list") Access the first element of the list. ...
vex){if(vex[1] == "This"){if(vex[2] > 2){return("CP")}else{return("QM")}}else if(vex[1] == "That"){return("BS")}else if(vex[1] == "The Other"){if(vex[2] == 4){return("FP")}else{return("DT")}}}results <- apply(df,1,applyF)df$Result <- factor(unlist(...
print(list_data[1]) # Access the thrid element. As it is also a list, all its elements will be printed. print(list_data[3]) # Access the list element using the name of the element. print(list_data$A_Matrix) 当我们上面的代码执行时,它产生以下结果: ...
print(merged.list) 1. 2. 3. 4. 5. 6. 7. 8. 9. 列表转向量 列表可以转换为向量,可以在将列表转换为向量之后应用对向量的所有算术运算 使用**unlist()**函数,将列表作为输入并生成向量。 # Create lists. list1 <- list(1:5) print(list1) list2 <-list(10:14) print(list2) # Convert ...
列表是R语言对象,它包含不同类型的元素,如数字,字符串,向量和其中的另一个列表。 列表还可以包含矩阵或函数作为其元素。 列表是使用list()函数创建的。创建列表 以下是创建...
list_data <- list(c("Jan","Feb","Mar"), matrix(c(3,9,5,1,-2,8), nrow=2), list("green",12.3)) # Give names to the elements in the list. names(list_data) <- c("1st Quarter", "A_Matrix", "A Inner list") # Access the first element of the list. ...