简体   繁体   English

如何用另一个值替换数据框中的值

[英]How to replace values in a data frame with another value

I have huge data set.我有庞大的数据集。 The columns contain values like A,B,C,D,E,F,G,H and I need to replace them with 1,2,3,4...这些列包含A,B,C,D,E,F,G,H等值,我需要用1,2,3,4...

[1] "C" "C" "C" "C" "C" "A" "H" "G" "G" "G" "G" "G" "G" "G" "C" "C" "C" "C" "C"
[20] "C" "B" "B" "B" "H" "H" "H" "H" "H" "H" "G" "C" "A" "A" "A" "A" "A" "A" "A"
[30]----

Another similar problem is values in one column are more than 1000 and I need to replace them by unique numbers.另一个类似的问题是一列中的值超过1000 ,我需要用唯一的数字替换它们。

try replace尝试replace

replace function examples 替换函数示例

in your case eg在你的情况下,例如

replace(df, "A", 1) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用另一个值将列中的值替换为数据框(对所有值都相同) - replace values in a column into Data Frame with another value (same for all) R 中是否有方法将一个数据帧中的值替换为另一个数据帧中的相关值? - Is there method in R to replace values in one data frame with a related value from another data frame? 有条件地将数据框中的值替换为另一个数据框中的值 - Conditionally replace values in a data frame with values from another data frame 从另一个数据框中的值替换一个数据框中的值 - Replace values in one data frame from values in another data frame 将值替换为另一个数据帧的值 - Replace a value by a value another data-frame 如何通过匹配R中的一个列值来用另一个数据帧替换数据帧值? - How to replace the data frame value with another data frame by matching one column value in R? 将一个数据框的索引值替换为另一个数据框的日期 - Replace index values of one data frame with dates of another data frame 根据另一个数据框替换数据框中的值 - replace value in dataframe based on another data frame 将一个数据框中的值替换为另一个 - Replace value in one data frame from another 如何通过滞后日期和 ID 根据另一个数据框替换数据框中某列的某些值? - How to replace some values of a column in a data frame based on another data frame through a lagged date and ID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM