R编程数据类型转换

时间:2017-06-21 12:05:15

标签: r variables callback type-conversion

 # Assigning a value to the variable my_apples
my_apples <- 5 

# Fixing the assignment of my_oranges
my_oranges <- "six" 

# Creating the variable my_fruit and printing it out
my_fruit <- my_apples + my_oranges 
my_fruit

尝试通过为变量my_oranges指定文本值来添加“apples”和“oranges”。 请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

您无法为添加添加数值和文本值。如果两个变量都是数字/整数,则可以将这些值相加。如果两个变量都是字符串,则可以使用paste()

添加它们
my_apples <- 5 


# Fixing the assignment of my_oranges
my_oranges <- 6

# Creating the variable my_fruit and printing it out
my_fruit <- my_apples + my_oranges 


my_apples <- "five"


# Fixing the assignment of my_oranges
my_oranges <- "six"

# Creating the variable my_fruit and printing it out
my_fruit <- paste0(my_apples,my_oranges) 

你可以看到?粘贴功能并查看崩溃和sep参数

答案 1 :(得分:0)

x<-c(1:100)
x[41:50] will give you the output. everything is a list in r.