[R] Help with strings
André Luis Neves
@ndr|u|@ @end|ng |rom u@|bert@@c@
Tue Sep 29 22:23:47 CEST 2020
Dear all,
I have had difficulties copying the word "alcohol" in the "vehicle" column
to replace the string in the column "accident_type". It is a huge list but
I have prepared a workable and simple example below and the desired
output. I am sure you guys can give me some advice on how to deal with
this.
sapply( all_files, function(x) dim(x))
[,1] [,2] [,3] [,4]
[1,] 89563 69295 67446 39709
[2,] 33 33 33 33
###Simple List
A= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "byke", "alcohol",
"motocycle"), c("alcohol", "cell_phone", "some_string", "fog"))
colnames(A) <- c("id", "km","vehicle","accident_cause")
A
B= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car",
"motocycle"), c("alcohol", "some_string", "rain", "fog"))
colnames(B) <- c("id", "km", "vehicle", "accident_type")
B
C= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car",
"alcohol"), c("alcohol", "some_string", "rain", "some_string"))
colnames(C) <- c("id", "km", "vehicle", "accident_type")
C
mylist <- list(A=A,B=B,C=C)
mylist
###Desired output
A= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "byke", "alcohol",
"motocycle"), c("alcohol", "cell_phone", "alcohol", "fog"))
colnames(A) <- c("id", "km","vehicle","accident_cause")
A
B= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car",
"motocycle"), c("alcohol", "alcohol", "rain", "fog"))
colnames(B) <- c("id", "km", "vehicle", "accident_type")
B
C= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car",
"alcohol"), c("alcohol", "alcohol", "rain", "alcohol"))
colnames(C) <- c("id", "km", "vehicle", "accident_type")
C
mylist <- list(A=A,B=B,C=C)
mylist
##Thank you very much,
--
Andre
[[alternative HTML version deleted]]
More information about the R-help
mailing list