我如何命名我的字符串中的东西?
How do I name stuff in my character string?
我是 R 的新手,所以我对基础知识有点困惑。目前,我有一个使用以下代码创建的字符串:
coldf <- character (length=2500)
我想更改字符中的内容。对于每五十个字符,我想将其更改为其他内容。快速浏览一些我想改变的东西是苹果、香蕉、梨和橙子。最后,我希望我的字符串是这样的:
“apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” "banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana" “pear”... etc
您似乎在使用 rep()
函数。它具有三种基本用法:
- 通过多次将向量连接到自身来重复一个向量
- 通过将每个元素重复多次来重复向量
- 通过将不同的元素重复不同的次数来重复向量
举例说明:
x = letters[1:5]
# 1
rep(x, 4)
# [1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" "b" "c" "d" "e"
# 2
rep(x, each = 4)
# [1] "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "c" "d" "d" "d" "d" "e" "e" "e" "e"
# 3
rep(x, 5:1)
# [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "d" "d" "e"
我是 R 的新手,所以我对基础知识有点困惑。目前,我有一个使用以下代码创建的字符串:
coldf <- character (length=2500)
我想更改字符中的内容。对于每五十个字符,我想将其更改为其他内容。快速浏览一些我想改变的东西是苹果、香蕉、梨和橙子。最后,我希望我的字符串是这样的:
“apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” “apple” "banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana” “banana" “pear”... etc
您似乎在使用 rep()
函数。它具有三种基本用法:
- 通过多次将向量连接到自身来重复一个向量
- 通过将每个元素重复多次来重复向量
- 通过将不同的元素重复不同的次数来重复向量
举例说明:
x = letters[1:5]
# 1
rep(x, 4)
# [1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" "b" "c" "d" "e"
# 2
rep(x, each = 4)
# [1] "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "c" "d" "d" "d" "d" "e" "e" "e" "e"
# 3
rep(x, 5:1)
# [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "d" "d" "e"