两个向量的组合用于许多目的,例如执行双向ANOVA,显示数据表或对数据进行可视表示。通过使用粘贴和表示功能,可以在R中使用许多特殊字符创建组合。
考虑下面的向量类和名称。
> Class<-c("Stats","Maths","Chem","Physics","O-R") > Class [1] "Stats" "Maths" "Chem" "Physics" "O-R" > Names<-c(101,102,103,104,105) > Names [1] 101 102 103 104 105
假设我们要以新向量包含Stats | 101,Stats | 102等的方式组合类和名称。另外,我们希望对不同的特殊字符执行相同的操作。
我们可以通过使用paste和rep函数并定义不同的分隔符来做到这一点,如下所示-
> paste(rep(Class, each = length(Name)), Name, sep = "|") [1] "Stats|101" "Stats|102" "Stats|103" "Stats|104" "Stats|105" "Maths|101" "Maths|102" "Maths|103" "Maths|104" "Maths|105" "Chem|101" [12] "Chem|102" "Chem|103" "Chem|104" "Chem|105" "Physics|101" "Physics|102" "Physics|103" "Physics|104" "Physics|105" "O-R|101" "O-R|102" [23] "O-R|103" "O-R|104" "O-R|105" > paste(rep(Class, each = length(Name)), Name, sep = ".") [1] "Stats.101" "Stats.102" "Stats.103" "Stats.104" "Stats.105" "Maths.101" "Maths.102" "Maths.103" "Maths.104" "Maths.105" "Chem.101" [12] "Chem.102" "Chem.103" "Chem.104" "Chem.105" "Physics.101" "Physics.102" "Physics.103" "Physics.104" "Physics.105" "O-R.101" "O-R.102" [23] "O-R.103" "O-R.104" "O-R.105" > paste(rep(Class, each = length(Name)), Name, sep = "-") [1] "Stats-101" "Stats-102" "Stats-103" "Stats-104" "Stats-105" "Maths-101" "Maths-102" "Maths-103" "Maths-104" "Maths-105" "Chem-101" [12] "Chem-102" "Chem-103" "Chem-104" "Chem-105" "Physics-101" "Physics-102" "Physics-103" "Physics-104" "Physics-105" "O-R-101" "O-R-102" [23] "O-R-103" "O-R-104" "O-R-105" > paste(rep(Class, each = length(Name)), Name, sep = "&") [1] "Stats&101" "Stats&102" "Stats&103" "Stats&104" "Stats&105" "Maths&101" "Maths&102" "Maths&103" "Maths&104" "Maths&105" "Chem&101" [12] "Chem&102" "Chem&103" "Chem&104" "Chem&105" "Physics&101" "Physics&102" "Physics&103" "Physics&104" "Physics&105" "O-R&101" "O-R&102" [23] "O-R&103" "O-R&104" "O-R&105" > paste(rep(Class, each = length(Name)), Name, sep = "*") [1] "Stats*101" "Stats*102" "Stats*103" "Stats*104" "Stats*105" "Maths*101" "Maths*102" "Maths*103" "Maths*104" "Maths*105" "Chem*101" [12] "Chem*102" "Chem*103" "Chem*104" "Chem*105" "Physics*101" "Physics*102" "Physics*103" "Physics*104" "Physics*105" "O-R*101" "O-R*102" [23] "O-R*103" "O-R*104" "O-R*105" > paste(rep(Class, each = length(Name)), Name, sep = "@") [1] "Stats@101" "Stats@102" "Stats@103" "Stats@104" "Stats@105" "Maths@101" "Maths@102" "Maths@103" "Maths@104" "Maths@105" "Chem@101" [12] "Chem@102" "Chem@103" "Chem@104" "Chem@105" "Physics@101" "Physics@102" "Physics@103" "Physics@104" "Physics@105" "O-R@101" "O-R@102" [23] "O-R@103" "O-R@104" "O-R@105" > paste(rep(Class, each = length(Name)), Name, sep = "!") [1] "Stats!101" "Stats!102" "Stats!103" "Stats!104" "Stats!105" "Maths!101" "Maths!102" "Maths!103" "Maths!104" "Maths!105" "Chem!101" [12] "Chem!102" "Chem!103" "Chem!104" "Chem!105" "Physics!101" "Physics!102" "Physics!103" "Physics!104" "Physics!105" "O-R!101" "O-R!102" [23] "O-R!103" "O-R!104" "O-R!105" > paste(rep(Class, each = length(Name)), Name, sep = "/") [1] "Stats/101" "Stats/102" "Stats/103" "Stats/104" "Stats/105" "Maths/101" "Maths/102" "Maths/103" "Maths/104" "Maths/105" "Chem/101" [12] "Chem/102" "Chem/103" "Chem/104" "Chem/105" "Physics/101" "Physics/102" "Physics/103" "Physics/104" "Physics/105" "O-R/101" "O-R/102" [23] "O-R/103" "O-R/104" "O-R/105" > paste(rep(Class, each = length(Name)), Name, sep = "==") [1] "Stats==101" "Stats==102" "Stats==103" "Stats==104" "Stats==105" "Maths==101" "Maths==102" "Maths==103" "Maths==104" "Maths==105" [11] "Chem==101" "Chem==102" "Chem==103" "Chem==104" "Chem==105" "Physics==101" "Physics==102" "Physics==103" "Physics==104" "Physics==105" [21] "O-R==101" "O-R==102" "O-R==103" "O-R==104" "O-R==105" > paste(rep(Class, each = length(Name)), Name, sep = "#") [1] "Stats#101" "Stats#102" "Stats#103" "Stats#104" "Stats#105" "Maths#101" "Maths#102" "Maths#103" "Maths#104" "Maths#105" "Chem#101" [12] "Chem#102" "Chem#103" "Chem#104" "Chem#105" "Physics#101" "Physics#102" "Physics#103" "Physics#104" "Physics#105" "O-R#101" "O-R#102" [23] "O-R#103" "O-R#104" "O-R#105" > paste(rep(Class, each = length(Name)), Name, sep = "^") [1] "Stats^101" "Stats^102" "Stats^103" "Stats^104" "Stats^105" "Maths^101" "Maths^102" "Maths^103" "Maths^104" "Maths^105" "Chem^101" [12] "Chem^102" "Chem^103" "Chem^104" "Chem^105" "Physics^101" "Physics^102" "Physics^103" "Physics^104" "Physics^105" "O-R^101" "O-R^102" [23] "O-R^103" "O-R^104" "O-R^105" > paste(rep(Class, each = length(Name)), Name, sep = "_") [1] "Stats_101" "Stats_102" "Stats_103" "Stats_104" "Stats_105" "Maths_101" "Maths_102" "Maths_103" "Maths_104" "Maths_105" "Chem_101" [12] "Chem_102" "Chem_103" "Chem_104" "Chem_105" "Physics_101" "Physics_102" "Physics_103" "Physics_104" "Physics_105" "O-R_101" "O-R_102" [23] "O-R_103" "O-R_104" "O-R_105" > paste(rep(Class, each = length(Name)), Name, sep = ">") [1] "Stats>101" "Stats>102" "Stats>103" "Stats>104" "Stats>105" "Maths>101" "Maths>102" "Maths>103" "Maths>104" "Maths>105" "Chem>101" [12] "Chem>102" "Chem>103" "Chem>104" "Chem>105" "Physics>101" "Physics>102" "Physics>103" "Physics>104" "Physics>105" "O-R>101" "O-R>102" [23] "O-R>103" "O-R>104" "O-R>105" > paste(rep(Class, each = length(Name)), Name, sep = "+") [1] "Stats+101" "Stats+102" "Stats+103" "Stats+104" "Stats+105" "Maths+101" "Maths+102" "Maths+103" "Maths+104" "Maths+105" "Chem+101" [12] "Chem+102" "Chem+103" "Chem+104" "Chem+105" "Physics+101" "Physics+102" "Physics+103" "Physics+104" "Physics+105" "O-R+101" "O-R+102" [23] "O-R+103" "O-R+104" "O-R+105" > paste(rep(Class, each = length(Name)), Name, sep = "()") [1] "Stats()101" "Stats()102" "Stats()103" "Stats()104" "Stats()105" "Maths()101" "Maths()102" "Maths()103" "Maths()104" "Maths()105" [11] "Chem()101" "Chem()102" "Chem()103" "Chem()104" "Chem()105" "Physics()101" "Physics()102" "Physics()103" "Physics()104" "Physics()105" [21] "O-R()101" "O-R()102" "O-R()103" "O-R()104" "O-R()105" > paste(rep(Class, each = length(Name)), Name, sep = "~") [1] "Stats~101" "Stats~102" "Stats~103" "Stats~104" "Stats~105" "Maths~101" "Maths~102" "Maths~103" "Maths~104" "Maths~105" "Chem~101" [12] "Chem~102" "Chem~103" "Chem~104" "Chem~105" "Physics~101" "Physics~102" "Physics~103" "Physics~104" "Physics~105" "O-R~101" "O-R~102" [23] "O-R~103" "O-R~104" "O-R~105" > paste(rep(Class, each = length(Name)), Name, sep = "?") [1] "Stats?101" "Stats?102" "Stats?103" "Stats?104" "Stats?105" "Maths?101" "Maths?102" "Maths?103" "Maths?104" "Maths?105" "Chem?101" [12] "Chem?102" "Chem?103" "Chem?104" "Chem?105" "Physics?101" "Physics?102" "Physics?103" "Physics?104" "Physics?105" "O-R?101" "O-R?102" [23] "O-R?103" "O-R?104" "O-R?105" > paste(rep(Class, each = length(Name)), Name, sep = "<>") [1] "Stats<>101" "Stats<>102" "Stats<>103" "Stats<>104" "Stats<>105" "Maths<>101" "Maths<>102" "Maths<>103" "Maths<>104" "Maths<>105" [11] "Chem<>101" "Chem<>102" "Chem<>103" "Chem<>104" "Chem<>105" "Physics<>101" "Physics<>102" "Physics<>103" "Physics<>104" "Physics<>105" [21] "O-R<>101" "O-R<>102" "O-R<>103" "O-R<>104" "O-R<>105"
本文向大家介绍如何在R中的特殊字符后删除部分字符串?,包括了如何在R中的特殊字符后删除部分字符串?的使用技巧和注意事项,需要的朋友参考一下 有时我们不需要整个字符串来进行分析,尤其是当它使分析变得复杂或毫无意义时。在这种情况下,可以从完整的字符串中删除我们认为不必要的字符串部分。例如,假设我们有一个字符串ID:00001-1,但我们不想在该字符串中使用-1,那么我们可以将其删除,这可以通过gsub
我有两个数据。表X和表Y。 列 X: Y 中的值列: 创建两个data.tables: 我设置了 X 和 Y 的键: 现在,我尝试通过X中的< code>id和Y中的< code>ID来连接X和Y: All引发错误,指出参数中的列名无效。 我查阅了data.table的手册,发现< code>merge函数不支持< code>by.x和< code>by.y参数。 如何在不更改列名的情况下通过不同
问题内容: 我该如何更换: “ã”和“ a” “é”和“ e” 在PHP中?这可能吗?我读过某处我可以使用基本字符的ascii值和重音符号的ascii值进行一些数学运算,但是现在找不到任何参考。 问题答案: 这个答案是不正确的。 编写它时,我不理解Unicode规范化。查看francadaval的评论和链接 签出Normalizer类来执行此操作。文档很好,所以我将其链接起来,而不是在这里重复:
我有以下XML结构: 我想将其转换(合并)为以下结构: 我们可以假设,对于相同的id,没有重复的节点或属性。 目前,我正在使用
关于字符集和替代字形 除键盘上可看到的字符之外,字体中还包括许多字符。根据字体的不同,这些字符可能包括连字、分数字、花饰字、装饰字、序数字、标题和文体替代字、上标和下标字符、变高数字和全高数字。字形是特殊形式的字符。例如,在某些字体中,大写字母 A 有几种形式可用,如花饰字或小型大写字母。 插入替代字形的方式有三种: 可以使用选择上下文菜单来查看和插入适用于所选字符的字形。 可以使用“字形”面板来
问题内容: 我有以下格式的数据: 因为拿起和零件应该真的很简单,但是我真的很努力。 我已经设法通过使用获得了部分,但正义将不适合我。 如何指定为分隔符? 问题答案: 只需使用定义您可以使用这些:,,或作为字段分隔 通常,您说。 测试